Overview
The SDK exposes three TTS clients — one per transport. They accept identical arguments and produce identical audio; they differ only in how quickly the first bytes reach you.REST — single response
Returns the complete audio asbytes. Pass output_file to also write it to disk; parent directories are created for you.
output_file, handle the bytes yourself — upload them, return them from a web handler, or push them into an audio device.
Parameters
Shared by all three clients unless noted.
Invalid combinations raise
ValueError locally — an unknown voice for the model, speed out of range, or language/speed passed with a non-timbre-v2.5 model.
SSE — progressive playback
synthesize_stream() yields raw PCM chunks as they are generated, so playback can start before synthesis finishes. Chunks carry no WAV header.
synthesize() collects every chunk and adds a RIFF header when the output is linear PCM WAV:
The header is added only for
encoding="linear_pcm" with container="wav". For mp3, oggopus, or telephony encodings, the server’s bytes are returned untouched — those formats carry their own framing.Realtime WebSocket — lowest latency
GnaniTTSRealtimeClient is async and offers three shapes, depending on how much control you need.
- Stream chunks
- Collect to a file
- Typed events
synthesize() is an async generator of audio bytes. Use it when audio should start playing immediately.Events
dataclass
The server has begun streaming audio.
dataclass
One binary audio chunk.
dataclass
Synthesis is finished and the connection is closing.
Each call to
synthesize(), synthesize_events(), or synthesize_and_collect() opens its own WebSocket connection and closes it when the server finishes. The async with block is for symmetry and future-proofing — it does not pool connections, so reusing one client instance across many calls is safe and cheap.Audio configuration
AudioConfig controls the output format. The default is 48 kHz, 16-bit mono WAV.
Common presets
ValueError before the request is sent.
Voices
timbre-v2.5 offers 42 voices. Each has a preferred language — match voice to language for best quality.
Query the list at runtime rather than hard-coding it:
Language and speed
Both aretimbre-v2.5-only. Passing either with another model raises ValueError.
language values: auto, hi-IN, en-IN, ta-IN, te-IN, kn-IN, ml-IN, mr-IN, bn-IN, gu-IN, pa-IN. Use auto to detect the language from the input script — this is also what the Hinglish voice expects.
Voice cloning
Generate a speaker embedding with the voice-clone embeddings endpoint, then pass it asSpeakerEmbedding. When present, voice is ignored.
SpeakerEmbedding works identically on all three clients.
Error handling
All except
ValueError inherit from GnaniTTSError.
Further Reading
- Python SDK overview — installation, auth, client selection
- Python SDK — Speech-to-Text
- Available Voices — full catalog with personas
- TTS REST · TTS SSE · TTS Realtime — endpoint references
- Text Formatting — pauses, numbers, and pronunciation control