Streaming TTS

Tips & Tricks

Practical advice for getting the best results from streaming TTS.


Choosing the right output format

  • Use pcm for real-time playback — no decoding overhead, lowest latency.
  • Use mulaw for 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 flush command to force immediate synthesis of buffered text.
  • Process audio chunks as they arrive rather than buffering everything in memory.
  • Reuse the AsyncShunyaClient context manager across multiple requests to avoid connection overhead.