Streaming TTS

Your First Stream

Stream audio from text in under five minutes using the ShunyaLabs Python SDK.


Quick start

The example below opens an async streaming connection, collects all audio chunks, and writes them to a PCM file.

ShunyaLabs Python SDK
import asyncio
from shunyalabs import AsyncShunyaClient
from shunyalabs.tts import TTSConfig

async def main():
    async with AsyncShunyaClient() as client:
        config = TTSConfig(model="zero-indic", voice="Varun", response_format="pcm")
        chunks = []
        async for audio in await client.tts.stream("Hello!", config=config):
            chunks.append(audio)
        with open("output.pcm", "wb") as f:
            f.write(b"".join(chunks))

asyncio.run(main())

What happens under the hood

  1. The SDK opens a WebSocket connection to wss://tts.shunyalabs.ai/ws/v1/audio/speech.
  2. Your text and TTSConfig are sent as a JSON message.
  3. The server begins streaming binary audio chunks as they are synthesized.
  4. The async generator yields each chunk, allowing real-time playback or buffering.
  5. When synthesis is complete, the server closes the stream.