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.

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.7.tar.gz (19.0 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.7-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bhashini_client-0.1.7.tar.gz
  • Upload date:
  • Size: 19.0 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.7.tar.gz
Algorithm Hash digest
SHA256 ba8001a9bacc9aa3ab5d48159287e137cf6348f2d345cc1b7afcef05803f1dce
MD5 d31e124ec52e836d2d6e6cfab5589ba3
BLAKE2b-256 060acafa5b6f00b44a1395480d70e3990291da4e0d487267b6689950070f0bd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bhashini_client-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 28a422af63dd0f6e7f250f202632a5050f0cd67367777302641738d469d7db0c
MD5 fe9a5c1d1fde249dd1cc180ce6dd9d24
BLAKE2b-256 b55c3767aaec9080ec0ea40f750ef39bd42d3f1dea630013ac1d6e5655b8b6d0

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