Skip to main content

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.
Always pass model="timbre-v2.5". The SDK’s built-in default is still timbre-v2.0, which the API no longer serves — a call without an explicit model fails with 400 and The supported models are "timbre-v2.5". Every example on this page sets it explicitly.

REST — single response

Returns the complete audio as bytes. Pass output_file to also write it to disk; parent directories are created for you.
Without 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.
If you want a finished file instead, 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.
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

Unsupported values raise 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:
Preview voices before integrating — open the Gnani TTS playground and filter by language, gender, and persona. Full descriptions are in the voice catalog.

Language and speed

Both are timbre-v2.5-only. Passing either with another model raises ValueError.
Accepted 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 as SpeakerEmbedding. When present, voice is ignored.
SpeakerEmbedding works identically on all three clients.

Error handling

All except ValueError inherit from GnaniTTSError.

Further Reading