Streaming TTS

Connection Lifecycle

Understand the three phases of a streaming TTS WebSocket session.


Lifecycle phases

PhaseSDK CallDescription
Connectclient.tts.stream()Opens a WebSocket connection and sends the text with config.
Receiveasync for audio in streamYields binary audio chunks as they arrive from the server.
DoneStopAsyncIterationThe server signals completion and the async generator exits.

Details

  • The SDK manages the WebSocket connection automatically inside AsyncShunyaClient.
  • Audio chunks are yielded as raw bytes in the format specified by response_format.
  • If the connection drops unexpectedly, the SDK raises a ConnectionError.