Endpoint
Connection Flow
- Client initiates WebSocket connection to
/ws - Server accepts connection and assigns a unique
connection_id - Client sends audio data as binary chunks
- Server buffers audio until minimum size is reached (20,000 bytes)
- Server processes audio and returns language detection result
- Connection closes after sending response
Message Protocol
Client to Server
Send raw audio data as binary WebSocket frames:Audio data in MP4 format. The server buffers chunks until at least 20,000 bytes are received (approximately 1 second of audio).
Audio Requirements
- Format: MP4 container with audio codec
- Minimum size: 20,000 bytes
- Recommended length: 4-15 seconds
- Bits per second: 16,000
Server to Client
The server sends JSON responses in two scenarios:Success Response
Always
"success" for successful detectionLanguage detection results
ISO 8601 timestamp when the response was generated
8-character unique identifier for this connection
Error Response
Always
"error" for failed detectionHuman-readable error description
ISO 8601 timestamp when the error occurred
8-character unique identifier for this connection
Implementation Examples
JavaScript
Python
Connection Tracking
Each WebSocket connection receives a unique 8-characterconnection_id (shortened UUID) used for:
- Request tracing in server logs
- Correlating responses with requests
- Debugging and monitoring
Metrics Impact
Each connection affects the following server metrics:active_connections: Incremented on connection, decremented on closetotal_requests: Incremented when connection is establishederrors: Incremented if processing failsprocessing_times: Audio processing duration added to rolling buffer
Connection Lifecycle
Fromwebsocket_manager.py:18-92:
- Accept: Connection accepted,
connection_idassigned - Increment:
active_connectionsandtotal_requestscounters updated - Buffer: Audio chunks buffered until minimum size reached
- Process: Audio sent to OpenAI API for transcription
- Respond: Language detection result sent as JSON
- Close: WebSocket closed,
active_connectionsdecremented
Error Handling
The endpoint handles these error scenarios:- Empty data chunks (ignored)
- OpenAI API errors (returned as error response)
- WebSocket disconnection (logged, metrics updated)
- General exceptions (logged, error response sent, connection closed)

