A Python client for interacting with Bhashini inference services (ASR, NMT, TTS).
Project description
bhashini-client
A simple Python client library for interacting with Bhashini inference APIs.
Currently supports:
- ASR (Automatic Speech Recognition)
- NMT (Machine Translation)
- TTS (Text-to-Speech)
Installation
pip install bhashini-client
Example Usage
from bhashini_client import BhashiniClient
client = BhashiniClient(api_key="api-key")
# --- ASR (Speech -> Text) ---
# Basic ASR (default settings)
asr_text = client.asr("https://example.com/audio.wav", "te")
print("ASR Basic:", asr_text)
# ASR with explicit configuration
asr_custom = client.asr(
"https://example.com/audio.wav",
"te",
serviceId="bhashini/ai4bharat/conformer-multilingual-asr",
samplingRate=44100,
)
print("ASR Custom:", asr_custom)
# --- NMT (Translate) ---
# Basic NMT: English -> Hindi
nmt_text = client.nmt("What are you doing?", "en", "hi")
print("NMT Basic:", nmt_text)
# NMT with processors (example: glossary)
nmt_proc = client.nmt(
"What are you doing?",
"en",
"hi",
numTranslation="False",
preProcessors=["glossary"],
postProcessors=["glossary"],
)
print("NMT With Processors:", nmt_proc)
# --- TTS (Text -> Speech) ---
# 1) Basic TTS: Hindi text with correct language code; saves to file
tts_basic_path = client.tts(
"मेरा नाम विहिर है",
"hi",
save_to="tts_basic.wav",
)
print("TTS Basic (file):", tts_basic_path)
# 2) TTS with explicit gender and custom speed/sampling
tts_tuned_path = client.tts(
"मेरा नाम विहिर है",
"hi",
gender="female",
speed=0.9, # 0.1 to 1.99
samplingRate=24000, # e.g., 16000/24000/44100/48000
save_to="tts_tuned.wav",
)
print("TTS Tuned (file):", tts_tuned_path)
# 3) TTS with processors
# Pre: text-normalization
# Post: high-compression (smaller file ~64kbps) or low-compression (~128kbps)
tts_proc_path = client.tts(
"मेरा नाम विहिर है",
"hi",
save_to="tts_processed.wav",
gender="female",
preProcessors=["text-normalization"],
postProcessors=["high-compression"],
)
print("TTS With Processors (file):", tts_proc_path)
# 4) TTS returning base64 audio instead of saving
tts_b64 = client.tts(
"मेरा नाम विहिर है",
"hi",
return_base64=True,
preProcessors=["text-normalization"],
postProcessors=["low-compression"],
)
print("TTS Base64 (first 60 chars):", tts_b64[:60] if isinstance(tts_b64, str) else tts_b64)
# 5) English TTS with a custom service (when using English text)
tts_en_path = client.tts(
"My name is Vihir",
"en",
save_to="tts_en.wav",
gender="female",
serviceId="ai4bharat/indic-tts-coqui-misc-gpu--t4",
)
print("TTS English (file):", tts_en_path)
# Notes:
# - If the server returns an audio URI instead of content, the client returns that URI string.
# - Use the correct source language for your text, e.g., "hi" for Hindi, "en" for English.
# - preProcessors and postProcessors are optional. See README for supported values.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bhashini_client-0.1.5.tar.gz
(8.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bhashini_client-0.1.5.tar.gz.
File metadata
- Download URL: bhashini_client-0.1.5.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3828222a1498c937c48634ab0499c949ab2066bfeef5dbe78c47cf28d9a6740c
|
|
| MD5 |
a0aff885568a5dcaeb4b80e14a08135f
|
|
| BLAKE2b-256 |
ded5bc4f9097d6b0f6ad92fe72cbdce47acda9e73616b25344067736f35cad9d
|
File details
Details for the file bhashini_client-0.1.5-py3-none-any.whl.
File metadata
- Download URL: bhashini_client-0.1.5-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92a366083a4ee3b63d254f0f75507a38fad518113e9c3021a3c7e9160e21744e
|
|
| MD5 |
06bcea3e114fce93a8f4fe7e28883841
|
|
| BLAKE2b-256 |
f6919a14c86b8724e0277c3141c4edbd8a2491e1eedc821698ca3d91551e1612
|