API Reference
Streaming WebSocket
Open a persistent WebSocket connection for real-time, chunk-by-chunk audio delivery as text is sent.
Connection Details
| PROPERTY | VALUE |
|---|---|
| Protocol | wss:// (WebSocket Secure) |
| URL | wss://tts.shunyalabs.ai/ws?api_key=YOUR_API_KEY |
| Auth | API key as api_key query parameter |
| Lifetime | Connection stays open until closed by client or server timeout |
Message Flow
The client sends JSON text frames and receives binary audio frames:
WebSocket Message Flow
Client Server
| |
| 1. Connect (WSS + api_key) |
|--------------------------------------->|
| |
| 2. Send config JSON frame |
| { |
| "model": "zero-indic", |
| "voice": "Nisha", |
| "response_format": "pcm", |
| "speed": 1.0 |
| } |
|--------------------------------------->|
| |
| 3. Send text JSON frame |
| { "input": "Hello, how are you?" } |
|--------------------------------------->|
| |
| 4. Receive binary audio chunks |
|<---------------------------------------|
|<---------------------------------------|
|<---------------------------------------|
| |
| 5. Receive end-of-stream marker |
|<---------------------------------------|
| |
| 6. Close connection |
|--------------------------------------->|Notes
- Audio chunks arrive as binary WebSocket frames. Buffer and play them as they arrive for lowest perceived latency.
- You can send multiple text frames on the same connection for sequential synthesis without reconnecting.
- If the API key is invalid, the server closes the connection with code
4001.