Skip to main content

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.

Extas

#To get all the service IDs available
services = client.list_nmt_services("en", "gu")
print(services)

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

bhashini_client-0.1.8.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bhashini_client-0.1.8-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file bhashini_client-0.1.8.tar.gz.

File metadata

  • Download URL: bhashini_client-0.1.8.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for bhashini_client-0.1.8.tar.gz
Algorithm Hash digest
SHA256 e8700757f70b5e54c6be474d9b23fa65d144ccb4a0869eee5099dba689e3c3e8
MD5 e113713a9e61560e5f30c4f594cc04e3
BLAKE2b-256 bd98aff2f43fa5662bacd6b9c09e3df4e5eadf25cade41dbb61cfd35966aafc1

See more details on using hashes here.

File details

Details for the file bhashini_client-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for bhashini_client-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 4e9932796e24f34336776f43ca7d069d58273768350fa57d9f1d4c741b06affc
MD5 5ab67d164275fcc5ed494af91ee4b914
BLAKE2b-256 11293cb44164712ee0c79021e52125ae9a6857c1551477cdb41815605d126be3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page