Python client for Gnani's speech AI platform (STT, TTS, and more)
pip install gnani-vachana==0.8.2 Copy PIP instructions
Official Python client by Gnani.ai. Build multilingual voice workflows with Speech-to-Text (STT) and Text-to-Speech (TTS) across REST, SSE streaming, and real-time WebSockets.
Gnani.ai is a production-ready speech AI platform with high-accuracy STT and low-latency TTS for 10+ Indian languages, with Timbre voices across REST, SSE, and WebSocket APIs.
from gnani.stt import GnaniSTTClient client = GnaniSTTClient(api_key="your-api-key") result = client.transcribe("audio.wav", language_code="hi-IN") print(result["transcript"]) STT Batch (many or long files) from gnani.stt import GnaniSTTBatchClient client = GnaniSTTBatchClient() # reads GNANI_API_KEY result = client.transcribe(["call1.wav", "call2.wav"], language_code="hi-IN") print(result[0].text) result.save("./outputs") # one JSON per file See Batch STT usage for step-by-step control, diarization, and webhooks.
import asyncio from gnani.stt import GnaniSTTStreamClient, StreamTranscriptEvent async def main(): async with GnaniSTTStreamClient(api_key="your-api-key", language_code="hi-IN") as stream: # Send audio chunks (raw PCM, 16-bit LE, 16 kHz, mono) with open("audio.pcm", "rb") as f: while chunk := f.read(1024): await stream.send_audio(chunk) await asyncio.sleep(0.032) # real-time pacing (32 ms per frame) # Iterate over events async for event in stream: if isinstance(event, StreamTranscriptEvent): print(event.text) asyncio.run(main()) TTS REST (single response) from gnani.tts import GnaniTTSClient, AudioConfig client = GnaniTTSClient(api_key="your-api-key") # timbre-v2.0 (default model) audio = client.synthesize( "नमस्ते, आप कैसे हैं?", voice="Pranav", model="timbre-v2.0", audio_config=AudioConfig(sample_rate=48000, encoding="linear_pcm", container="wav"), ) # timbre-v2.5 — language control + speed audio = client.synthesize( "नमस्ते, यह एक परीक्षण है।", voice="Nalini", model="timbre-v2.5", language="hi-IN", speed=1.0, audio_config=AudioConfig(container="mp3", sample_rate=48000, bitrate="128k"), ) with open("tts_output.mp3", "wb") as f: f.write(audio) TTS SSE Streaming (lower latency) from gnani.tts import GnaniTTSStreamClient, AudioConfig client = GnaniTTSStreamClient(api_key="your-api-key") audio = client.synthesize( "Hello from Gnani TTS", voice="Pranav", model="timbre-v2.0", audio_config=AudioConfig(sample_rate=48000, encoding="linear_pcm", container="wav"), output_file="tts_sse.wav", ) TTS Realtime WebSocket (lowest latency) import asyncio from gnani.tts import GnaniTTSRealtimeClient, AudioConfig async def main(): async with GnaniTTSRealtimeClient(api_key="your-api-key") as client: audio = await client.synthesize_and_collect( "Hello from Gnani TTS", voice="Pranav", model="timbre-v2.0", audio_config=AudioConfig(sample_rate=48000, encoding="linear_pcm", container="wav"), output_file="tts_realtime.wav", ) asyncio.run(main()) Authentication All APIs (STT REST, STT Realtime, TTS) require a single API key:
You need a Gnani API key. Gnani APIs have this.
export GNANI_API_KEY="your-api-key" from gnani.stt import GnaniSTTClient, GnaniSTTStreamClient from gnani.tts import GnaniTTSClient client = GnaniSTTClient() # picks up GNANI_API_KEY stream = GnaniSTTStreamClient() # picks up GNANI_API_KEY tts = GnaniTTSClient() # picks up GNANI_API_KEY Supported Languages STT Languages (Speech-to-Text) STT uses BCP-47 locale codes (e.g. hi-IN). For the full list of supported languages, see:
TTS uses the Timbre engine. Two model IDs are supported:
Migration: The former model name vachana-voice-v3 has been renamed to timbre-v2.0. Update any model="vachana-voice-v3" calls to model="timbre-v2.0" (or omit model to use the default).
42 Timbre voices across Hindi, English, Tamil, Telugu, Kannada, Malayalam, Marathi, Bengali, Gujarati, Punjabi, and Hinglish. Examples: Nalini, Kaveri, Asmita, Suhana, Poorvi.
from gnani.tts import GnaniTTSClient print(GnaniTTSClient.supported_voices()) # timbre-v2.0 (default) print(GnaniTTSClient.supported_voices(model="timbre-v2.5")) # 42 voices timbre-v2.5 optional controls Only timbre-v2.5 accepts the language and speed parameters:
voice is required for all Timbre models unless speaker_embedding is provided.
For the full list of supported languages, see TTS — Supported Languages.
result = client.transcribe("meeting.wav", language_code="en-IN") print(result["transcript"]) Transcribe from a file object with open("meeting.mp3", "rb") as f: result = client.transcribe(f, language_code="ta-IN") Transcribe raw bytes audio_bytes = download_audio_from_somewhere() result = client.transcribe_bytes( audio_bytes, filename="clip.wav", language_code="kn-IN" ) Custom request ID result = client.transcribe( "call.flac", language_code="hi-IN", request_id="my-trace-123" ) List supported languages for code, name in GnaniSTTClient.supported_languages().items(): print(f"{code}: {name}") Batch STT Usage Batch jobs run asynchronously: create, start, wait, fetch. transcribe() does all four. Limits: 100 files per job, 10 MB per file (ZIP: 50 MB). Larger files are not supported yet.
from gnani.stt import GnaniSTTBatchClient client = GnaniSTTBatchClient() # Files can be a path, a directory, a glob, a ZIP, bytes, a file object, or public URLs. result = client.transcribe("./recordings/", language_code="hi-IN,en-IN", speakers=2) for f in result: print(f.name, "OK" if f.ok else f"FAILED: {f.error}") if f.ok: for seg in f.segments: print(f" [{seg.start:.1f}-{seg.end:.1f}] speaker {seg.speaker}: {seg.text}") Step by step (long jobs, resuming later) job = client.create_job("./recordings/*.wav", language_code="hi-IN") # starts automatically print(job.id) # keep this to resume job.wait(timeout=3600, on_progress=lambda j: print(j.status, j.percent)) job = client.get_job(" ") # e.g. after a restart files = job.files() job.save("./outputs", text_files=True) language_code takes one code, several comma-separated (identified per speaker turn; the first is the fallback), or "auto". Other options: diarization, speakers (1-8), multi_channel, denoise, bias_words, bias_score, callback_url, start=False.
AsyncGnaniSTTBatchClient has the same methods, awaited. Transcripts are downloaded concurrently, so .text and .segments are plain attributes on what transcribe() returns (after job.files() call await f.load(), or pass load=True).
from gnani.stt import AsyncGnaniSTTBatchClient client = AsyncGnaniSTTBatchClient() result = await client.transcribe("./recordings/", language_code="hi-IN") print(result[0].text) await result.save("./outputs") async for job in client.list_jobs(status="COMPLETED"): print(job.id) wait() returns for COMPLETED and PARTIAL_FAILURE (check each BatchFile.ok) and raises BatchJobFailedError for FAILED, START_FAILED and CANCELLED, and BatchTimeoutError on timeout (the job keeps running). It polls every 10 s, the documented minimum.
All audio must be sent as raw PCM binary frames. No container format (WAV, MP3, etc.) is accepted mid-stream.
For the full WebSocket protocol reference, see STT Realtime — PCM Specification.
Every event includes a raw field with the full server JSON:
async for event in stream: print(event.raw) # dict with the complete server response Text-to-Speech Usage Input text is normalized server-side; see the Text Normalization Guide for symbols, numbers, and abbreviations.
from gnani.tts import DEFAULT_MODEL, SUPPORTED_MODELS print(DEFAULT_MODEL) # timbre-v2.0 print(sorted(SUPPORTED_MODELS)) # timbre-v2.0, timbre-v2.5 TTS REST from gnani.tts import GnaniTTSClient client = GnaniTTSClient(api_key="your-api-key") # Default audio_config uses sample_rate=48000 audio = client.synthesize("यह एक टेस्ट है", voice="Pranav", model="timbre-v2.0") with open("tts_rest.wav", "wb") as f: f.write(audio) TTS Streaming (SSE) Lower latency than REST — audio is streamed via Server-Sent Events.
from gnani.tts import GnaniTTSStreamClient, AudioConfig client = GnaniTTSStreamClient(api_key="your-api-key") # synthesize() collects all chunks and returns audio matching audio_config audio = client.synthesize( "Streaming TTS response", voice="Pranav", model="timbre-v2.0", audio_config=AudioConfig(sample_rate=48000, encoding="linear_pcm", container="wav"), output_file="tts_sse.wav", ) For chunk-by-chunk streaming (e.g. real-time playback), use synthesize_stream():
for audio_chunk in client.synthesize_stream("Hello!", voice="Pranav", model="timbre-v2.0"): play_audio(audio_chunk) # format depends on audio_config (PCM, OGG, MP3, etc.) TTS Realtime (WebSocket) Lowest latency — audio is streamed over a persistent WebSocket connection.
import asyncio from gnani.tts import GnaniTTSRealtimeClient, AudioConfig async def main(): async with GnaniTTSRealtimeClient(api_key="your-api-key") as client: # synthesize_and_collect() returns audio matching audio_config audio = await client.synthesize_and_collect( "Realtime TTS response", voice="Kaveri", model="timbre-v2.0", audio_config=AudioConfig(sample_rate=48000, encoding="linear_pcm", container="wav"), output_file="tts_realtime.wav", ) asyncio.run(main()) For chunk-by-chunk streaming (e.g. real-time playback):
async with GnaniTTSRealtimeClient(api_key="your-api-key") as client: async for audio_chunk in client.synthesize("Hello!", voice="Pranav", model="timbre-v2.0"): play_audio(audio_chunk) # format depends on audio_config (PCM, OGG, MP3, etc.) TTS timbre-v2.5 (expanded catalog) from gnani.tts import GnaniTTSClient, AudioConfig client = GnaniTTSClient(api_key="your-api-key") audio = client.synthesize( "Hello, this is a Timbre test.", voice="Kaveri", model="timbre-v2.5", language="en-IN", speed=1.0, audio_config=AudioConfig(container="mp3", sample_rate=48000, bitrate="128k"), ) The same model and language parameters work on GnaniTTSStreamClient (SSE) and GnaniTTSRealtimeClient (WebSocket) when using timbre-v2.5.
For telephony integrations (IVR, SIP), use 8 kHz A-law or μ-law:
Supported at all standard sample rates (8000–48000).
Supported combinations of container, encoding, sample_rate, and bitrate:
File extensions: Match the output file extension to your audio_config.container — use .wav for WAV, .mp3 for MP3, .ogg for OGG/Opus, .raw for raw PCM, .alaw / .ulaw for telephony.
from gnani.tts import ( SUPPORTED_ENCODINGS, # {"linear_pcm", "oggopus", "pcm_mulaw", "pcm_alaw"} SUPPORTED_CONTAINERS, # {"raw", "mp3", "wav", "ogg", "mulaw", "alaw"} SUPPORTED_BITRATES, # {"32k", "64k", "96k", "128k", "192k"} SUPPORTED_SAMPLE_RATES, # (8000, 16000, 22050, 24000, 44100, 48000) DEFAULT_SPEED, # 1.0 MIN_SPEED, # 0.85 MAX_SPEED, # 1.15 ) TTS Voices List voices for a specific model:
{ "success": true, "request_id": "req_abc123", "timestamp": "20251226_143052.123", "transcript": "नमस्ते, आप कैसे हैं?" } Realtime Streaming Connected:
{ "type": "connected", "message": "STT service ready — VAD service connected", "timestamp": "2024-01-15T10:30:00.000Z", "config": { "sample_rate": 16000, "chunk_size": 512 } } Transcript:
{ "type": "transcript", "timestamp": "2024-01-15T10:30:05.987Z", "text": "Hello, how are you today?", "audio_duration_ms": 2340, "segment_id": " ", "segment_index": " ", "latency": 320 } Error Handling from gnani.stt import ( AuthenticationError, InvalidAudioError, APIError, StreamConnectionError, StreamClosedError, StreamError, ) # REST errors try: result = client.transcribe("audio.wav", language_code="hi-IN") except AuthenticationError: print("Check your credentials") except InvalidAudioError as e: print(f"Bad audio file: {e}") except APIError as e: print(f"API error {e.status_code}: {e}") # Streaming errors try: async with GnaniSTTStreamClient(api_key="key") as stream: await stream.send_audio(chunk) except StreamConnectionError as e: print(f"Connection failed: {e}") except StreamClosedError as e: print(f"Stream already closed: {e}") except StreamError as e: print(f"Server error: {e} (at {e.timestamp})") TTS Errors from gnani.tts import ( GnaniTTSClient, GnaniTTSRealtimeClient, AuthenticationError, APIError, StreamConnectionError, StreamError, ) # REST / SSE errors try: audio = GnaniTTSClient(api_key="key").synthesize("Hello", voice="Pranav") except AuthenticationError: print("Check your API key") except APIError as e: print(f"TTS API error {e.status_code}: {e}") # WebSocket errors try: async with GnaniTTSRealtimeClient(api_key="key") as client: audio = await client.synthesize_and_collect("Hello", voice="Pranav") except StreamConnectionError as e: print(f"WebSocket connection failed: {e}") except StreamError as e: print(f"TTS stream error: {e}") Documentation Full API reference and guides are available at docs.gnani.ai.
This project is licensed under the MIT License -- see the LICENSE file for details.
All 2 files in this release have provenance metadata.
asr gnani indian-languages multilingual realtime speech-to-text sse streaming stt text-to-speech transcription tts websocket
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
All 2 files in this release have been uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.




