This project is a high-performance backend service developed in Go that converts WAV audio streams to FLAC format in real-time. The service leverages WebSocket connections to provide seamless streaming capabilities with minimal latency while maintaining high audio fidelity.
- 🔄 Real-Time Streaming: Processes continuous WAV audio streams and converts them to FLAC format on the fly
- 🌐 WebSocket Integration: Uses secure WebSocket (WSS) for bidirectional real-time data streaming
- ⚡ High Performance: Optimized for low-latency audio processing with minimal memory footprint
- 🚀 Scalable Architecture: Designed to handle multiple concurrent streams efficiently
- 🛠️ Containerized Deployment: Ready for deployment in Kubernetes environments
- ✅ Comprehensive Testing: Includes both unit and integration tests
wav-to-flac-service/
├── cmd/
│ └── main.go # Application entry point
├── handlers/
│ └── stream.go # WebSocket handler implementation
├── services/
│ └── conversion.go # Audio conversion logic
├── tests/
│ ├── conversion_test.go # Unit tests
│ └── integration_test.go # Integration tests
├── utils/
│ └── logger.go # Logging utilities
└── README.md
- Go 1.17 or higher
- Docker
- FFmpeg (for local development)
- Kubernetes (optional, for deployment)
- Clone the repository
git clone https://github.com/ayushh2k/wav-to-flac-service.git
cd wav-to-flac-service
- Install dependencies
go mod tidy
- Run the server
go run cmd/main.go
- Build the image
docker build -t wav-to-flac-service .
- Run the container
docker run -p 8080:8080 wav-to-flac-service
- Tag and push the Docker image
docker tag wav-to-flac-service your-dockerhub-username/wav-to-flac-service:latest
docker push your-dockerhub-username/wav-to-flac-service:latest
- Create deployment configuration
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wav-to-flac-service
spec:
replicas: 3
selector:
matchLabels:
app: wav-to-flac-service
template:
metadata:
labels:
app: wav-to-flac-service
spec:
containers:
- name: wav-to-flac-service
image: your-dockerhub-username/wav-to-flac-service:latest
ports:
- containerPort: 8080
- Create service configuration
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: wav-to-flac-service
spec:
selector:
app: wav-to-flac-service
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
- Deploy to Kubernetes
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
- URL:
/stream
- Protocol:
WSS
- Description: Establishes a WebSocket connection for bidirectional audio streaming
- Data Flow:
- Client connects to WebSocket endpoint
- Client streams WAV audio data in chunks
- Server converts chunks to FLAC format
- Server streams converted FLAC data back to client
go test ./tests/conversion_test.go -v
go test ./tests/integration_test.go -v
sequenceDiagram
participant Client
participant WebSocket
participant Server
participant Converter
Client->>WebSocket: Connect
WebSocket->>Server: Establish Connection
loop Streaming Process
Client->>WebSocket: Send WAV Chunk
WebSocket->>Server: Receive WAV Chunk
Server->>Converter: Process WAV Chunk
Converter->>Server: Return FLAC Chunk
Server->>WebSocket: Send FLAC Chunk
WebSocket->>Client: Receive FLAC Chunk
end
Client->>WebSocket: Close Connection
WebSocket->>Server: End Stream
- Implements chunk-based processing to minimize memory usage
- Uses goroutines for concurrent stream handling
- Configurable buffer sizes for optimal performance tuning
- Efficient error handling and resource cleanup
-
Clone the repository
git clone https://github.com/ayushh2k/wav-to-flac-service.git cd wav-to-flac-service
-
Navigate to the client directory
cd client
-
Run the client
go run main.go -input ./assets/test.wav -output ./assets
-input
: Path to the input WAV file-output
: Output directory for the converted FLAC files (default: current directory)
This command will save the output flac stream in the ./assets directory when the client is run.