Overview
The WebSocket endpoint enables real-time audio streaming with low-latency. Unlike the REST API, audio chunks are delivered as they’re generated, making it ideal for:- Live voice assistants
- Real-time call center applications
- Interactive voice response (IVR) systems
- Any application requiring immediate audio feedback
Authentication
Pass your API key in theAuthorization header as a Bearer token when establishing the WebSocket connection.
Concurrency Model
Users can open multiple connections. The concurrency limit only applies when actively processing speech requests.
- You can maintain 10 open connections
- Only 5 can generate speech simultaneously
- Additional requests will throw 429 rate limit error
Request Format
ISO language code for the speech output.Supported languages:
en, hi, mr, ta, te, gu, kn, ml, bn, pa, od, asAvailable Voices
Example Request
Minimal Request
Response Messages
The server sends multiple message types during a speech generation request:Connection Established
Sent immediately after successful authentication.Audio Chunks
Streamed audio data. Multiple chunks are sent per request.Request Complete
Signals all audio has been sent.Error
Indicates a problem with the request.Error Codes
Complete Example
Best Practices
Connection Management
Connection Management
- Reuse WebSocket connections for multiple requests
- Implement automatic reconnection with exponential backoff
- Send periodic pings to keep connections alive (every 30 seconds)
- Close connections gracefully when no longer needed
Audio Handling
Audio Handling
- Buffer audio chunks before playback for smoother experience
- Default audio format: PCM 16-bit, 24kHz, mono
- Use Web Audio API for browser playback
- Consider using a streaming audio player for real-time playback
Error Handling
Error Handling
- Always handle the
errormessage type - Implement request timeouts (recommended: 30 seconds)
- Queue requests when concurrency limit is reached
- Log
request_idfor debugging and support

