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
- The SDK opens a WebSocket connection to
wss://tts.shunyalabs.ai/ws/v1/audio/speech. - Your text and
TTSConfigare sent as a JSON message. - The server begins streaming binary audio chunks as they are synthesized.
- The async generator yields each chunk, allowing real-time playback or buffering.
- When synthesis is complete, the server closes the stream.