TTS WebSocket
Real-time Text-to-Speech synthesis via WebSocket streaming with full-duplex bidirectional communication.Endpoint
Authentication
Query parameter authentication: Example:Protocol Overview
Connection Sequence
1. Connect
2. Receive Authentication Message
3. Receive Connection Established
string
Service name:
"tts"integer
Your user ID
number
Available credits
string
Workspace name
Client → Server Messages
1. create_context
Must be the first message. Initializes the TTS session with voice and audio settings.LINEAR16 at 16000 Hz.
Note:Limits:MULAW/ULAWonly works at8000Hz. Using other sample rates with MULAW falls back to LINEAR16 @ 16kHz. Similarly,OGG_OPUSonly works at24000Hz.
2. send_text
Append text to the internal buffer. Text is accumulated until aflush_context or close_context is received.
send_text messages to build up text incrementally (e.g., from an LLM token stream):
- Sentence boundary detection for natural chunk splits
- Newline characters (
\n) are treated as hard paragraph boundaries - Mixed-language text (e.g., English + Hindi) is chunked per paragraph to prevent early EOS
3. flush_context
Triggers synthesis of all accumulated text. The server responds withaudio_chunk messages followed by flush_completed (only on success — if synthesis fails, an error message is sent instead with no flush_completed).
4. close_context
Flushes any remaining text, sends final audio, and closes the WebSocket connection.Server → Client Messages
context_created
Confirms the session was initialized successfully.audio_chunk
Contains a chunk of synthesized audio. Multiple chunks are sent per flush. Each chunk is streamed as soon as it’s decoded for minimum latency.string
Session identifier
string
Base64-encoded audio bytes
audio_config:
flush_completed
Signals that all audio for the flushed text has been sent. Only sent on successful synthesis — if synthesis fails, anerror is sent instead.
context_closed
Confirms the session is closed. The WebSocket connection closes after this message.error
Sent if synthesis fails or a protocol violation occurs.Complete Example
Real-time Playback (Browser)
For low-latency playback as chunks arrive (instead of waiting for all chunks), use the Web Audio API with scheduledAudioBufferSourceNode:
LLM Integration Pattern
When streaming tokens from an LLM into TTS:Audio Format Notes
For telephony integration (Twilio, etc.), use
MULAW at 8000 Hz:
OGG_OPUS at 24000 Hz:
Important: OGG_OPUS chunks are individually wrapped OGG files. To merge for download, decode each chunk independently (e.g., via AudioContext.decodeAudioData()) and concatenate the PCM output. Do not concatenate raw OGG bytes.
Supported Languages
The TTS model supports synthesis in multiple Indic languages and English. The language is auto-detected from the input text — no explicit language parameter is needed.
Mixed-language text is supported. Use newlines (
\n) to separate paragraphs in different languages for best results.
Default Voice
The default voice ID is:Context Management
Reuse Context
Keep a context open for multiple syntheses:Multiple Contexts
You can create multiple contexts in one connection:Pricing
- Rate: $0.00002 per character
- Minimum: $0.01 per context
- Billing: Per character synthesized
Error Codes
Testing
Related
- STT WebSocket - Speech-to-Text endpoint
- Voices API - Get available voices
- WebSocket API Reference - Complete documentation