Python SDK for Bhashini inference APIs with unified support for ASR, NMT, TTS, OCR, NER, speaker services, normalization, and image-language workflows.
Project description
Bhashini Client SDK (Python)
bhashini-client-sdk is a Python SDK for working with Bhashini inference APIs through a unified BhashiniClient.
It provides a clean interface for speech, text, speaker, normalization, OCR, and image-language workflows while keeping validation, payload construction, model routing, and response parsing inside dedicated service modules.
Overview
Supported service categories:
| Category | Services |
|---|---|
| Speech / Audio | ASR, TTS, Audio Language Detection, Speaker Diarization, Speaker Enrollment, Speaker Verification, Voice Cloning, Denoiser |
| Text | NMT, Transliteration, Text Language Detection, Text Normalization, Inverse Text Normalization, NER |
| Vision | OCR, Image Language Detection |
Each service includes:
- input validation
- payload construction
- API dispatch through a shared request handler
- response parsing into simple SDK outputs
Installation
Requirements:
- Python
3.8+
Install from PyPI:
pip install bhashini-client-sdk
Authentication
Set the API key through BHASHINI_API_KEY or pass it directly to the client.
Environment variable:
$env:BHASHINI_API_KEY="your_api_key"
Or in code:
from bhashini_client import BhashiniClient
client = BhashiniClient(api_key="your_api_key")
Quick Start
from bhashini_client import BhashiniClient
client = BhashiniClient()
print(client.text_language_detection("Hello world"))
print(client.nmt("Hello", "en", "hi"))
print(client.tts("Hello from Bhashini", "en", output_file="output.wav"))
print(client.asr(r"C:\path\sample.wav", "hi"))
Public Client Methods
| Method | Purpose | Return Type |
|---|---|---|
client.asr(audio_input, source_lang) |
Speech to text | str transcription |
client.nmt(text, source_lang, target_lang) |
Translation | str translated text |
client.tts(text, source_lang, gender="female", output_file="output.wav") |
Text to speech | output file path str |
client.transliteration(text, source_lang, target_lang) |
Script conversion | transliterated text str |
client.text_language_detection(text) |
Text language detection | language code str |
client.audio_language_detection(audio_input) |
Audio language detection | language code str |
client.ocr(image_path, source_lang) |
OCR from local image | extracted text str |
client.ner(text, source_lang) |
Named entity recognition | dict with entities |
client.speaker_diarization(audio_input) |
Speaker segmentation | list of speaker blocks |
client.speaker_enrollment(audio_input, speaker_name) |
Speaker profile creation | speaker ID str |
client.speaker_verification(audio_input, speaker_id) |
Speaker verification | verification result |
client.voice_cloning(text, ref_text, ref_audio_input, source_lang="te", output_file="voice_clone_output.wav") |
Voice cloning | output file path str |
client.image_language_detection(image_input) |
Image language detection | language code str |
client.text_normalization(text, source_lang="en") |
Text normalization | normalized text str |
client.inverse_text_normalization(text, source_lang="en") |
ITN | normalized text str |
client.denoiser(audio_input, output_file="denoised_output.wav") |
Audio denoising | output file path str or audio URI str |
Service Highlights
ASR
- Supports local WAV input, base64 audio, and audio URI input
- Supports validated pre-processors:
vad,denoiser - Supports post-processors:
itn,punctuation - Automatically normalizes mismatched WAV sampling rates to
16000 Hzbefore dispatch
NMT
- Supports translation across validated language pairs
- Supports optional
glossary,domain,gender,enable_number_translation, andprofanity_filter - Supports
pre_processors=["html"] - Supports
post_processors=["glossary"]
TTS
- Generates WAV output files through the public client
- Advanced service usage supports
speed,speaker_name,text_normalization,profanity_filter, andreturn_base64
Transliteration
- Supports suggestion count, sentence mode, and
numeric_transliteration
Text Language Detection
- Detects the top language code from input text
Audio Language Detection
- Supports local WAV input, base64 audio, and audio URI input
- Automatically normalizes mismatched WAV sampling rates to
16000 Hzbefore dispatch
OCR
- Extracts text from a local image file
NER
- Extracts named entities and returns a normalized
{"entities": [...]}structure
Speaker Services
- Enrollment supports local audio, base64 audio, and audio URI input
- Verification supports local audio, base64 audio, and audio URI input
- Diarization returns speaker segments with timestamps
Voice Cloning
- Generates speech from reference text and reference audio
Image Language Detection
- Supports local image path, public image URL, and base64 image content
Text Normalization and ITN
- Dedicated normalization endpoints for written-form cleanup and inverse text normalization
Denoiser
- Supports local audio, base64 audio, and audio URI input
Model Discovery
from bhashini_client import get_models_info, get_available_models
print(get_models_info("asr"))
print(get_available_models("asr", language="hi"))
print(get_available_models("nmt", language=("en", "hi")))
print(get_available_models("tts", language="en"))
Error Handling
Services return structured string errors with these prefixes:
Input Error:Validation Error:API Error:
Package Contents
bhashini_client.BhashiniClientbhashini_client.get_models_infobhashini_client.get_available_models
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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_sdk-0.2.3.tar.gz.
File metadata
- Download URL: bhashini_client_sdk-0.2.3.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32506fcafeb0ce1d2bea005c9a16470299fd733d1d07d9d50d1162c43a098642
|
|
| MD5 |
dadbe955480bf73690247739f5ace5bf
|
|
| BLAKE2b-256 |
5666247d8b03a376b7d49fd618ee9e2b6e6c457f36445410ddc012d43b0b1dbc
|
File details
Details for the file bhashini_client_sdk-0.2.3-py3-none-any.whl.
File metadata
- Download URL: bhashini_client_sdk-0.2.3-py3-none-any.whl
- Upload date:
- Size: 37.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d87a498b1abcc6538994b9347960ba64c59c47fe5be2cebeaf19bc67d5c04bc2
|
|
| MD5 |
57ab43349eeb70938e31f6a44a96d6e2
|
|
| BLAKE2b-256 |
fb98fc2336c0ff6e95fe9163bedcce9bf6f7e033763fecf509a99e9ff7905c4d
|