Streaming TTS
Tips & Tricks
Practical advice for getting the best results from streaming TTS.
Choosing the right output format
- Use
pcmfor real-time playback — no decoding overhead, lowest latency. - Use
mulawfor telephony integrations (Twilio, IVR, PSTN) — standard 8kHz codec. - Use
stream_to_file()for long-form content — handles chunk collection and file writing automatically. - Implement reconnection logic for production deployments — WebSocket connections can drop due to network issues.
Performance tips
- Send complete sentences for better prosody and more natural-sounding speech.
- Use the
flushcommand to force immediate synthesis of buffered text. - Process audio chunks as they arrive rather than buffering everything in memory.
- Reuse the
AsyncShunyaClientcontext manager across multiple requests to avoid connection overhead.