TTS WebSocket API
Real-time Text-to-Speech synthesis via WebSocket streaming with full-duplex bidirectional communication.🚀 Quick Start (Copy & Paste)
- ✅ Authenticated
- ✅ Context created
- 🔊 Audio chunk: 1024 bytes (multiple times)
- ✅ All audio received!
- ✅ Complete!
- 💾 Saved: output.pcm
📖 How It Works (5 Simple Steps)
- Connect with your API key
- Create a context with voice settings
- Send your text message
- Flush to trigger synthesis
- Close when done (receive audio file)
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.Note:Limits:MULAW/ULAWonly works at8000Hz.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):
3. flush_context
Triggers synthesis of all accumulated text. The server responds withaudio_chunk messages followed by 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.string
Session identifier
string
Base64-encoded audio bytes
audio_config:
flush_completed
Signals that all audio for the flushed text has been sent.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
Audio Configuration
For telephony integration (Twilio, etc.), use
MULAW at 8000 Hz.
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:Supported Languages
The TTS model supports synthesis in multiple Indic languages and English. The language is auto-detected from the input text.Pricing
- Rate: $0.00002 per character
- Minimum: $0.01 per context
- Billing: Per character synthesized
Related
- STT WebSocket - Speech-to-Text endpoint
- WebSocket Quick Start - Get started guide
- WebSocket Playground - Test in browser
- Voices API - Get available voices