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
string
required
Must be
"speech" for TTS requests.string
required
The text to convert to speech.
string
required
The specific voice ID to use for synthesis. See available voices below.
string
default:"en"
ISO language code for the speech output.Supported languages:
en, hi, mr, ta, te, gu, kn, ml, bn, pa, od, asboolean
default:true
If
true, adds a WAV header to the audio stream for immediate playback.number
default:24000
Audio sample rate in Hz.Supported values:
8000, 16000, 24000number
Playback speed multiplier. Range:
0.5 to 2.0, where 1.0 is normal speed.string
Optional custom identifier for tracking requests. Auto-generated if not provided.
Available 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.string
Always
"connected"string
Unique identifier for this WebSocket connection.
Audio Chunks
Streamed audio data. Multiple chunks are sent per request.string
Always
"audio_chunk"string
The request identifier.
integer
Zero-indexed position in the audio stream.
string
Base64-encoded audio data (PCM 16-bit, 24kHz mono by default).
Request Complete
Signals all audio has been sent.string
Always
"complete"string
The request identifier.
integer
Total number of audio chunks sent.
integer
Characters processed (for billing verification).
Error
Indicates a problem with the request.string
Always
"error"string
The request identifier (if available).
string
Error code for programmatic handling.
string
Human-readable error description.
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

