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

Uploaded Python 3

File details

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

File metadata

  • Download URL: bhashini_client-0.1.6.tar.gz
  • Upload date:
  • Size: 12.5 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.6.tar.gz
Algorithm Hash digest
SHA256 0260fa7c3b06c4fe90560bd475f318067cc0957e3520bdfbbe604821c7ce8ccd
MD5 60fa57abc0d11e701e13fe74540fbe43
BLAKE2b-256 c2b7742e813366d23a624df88d1d0b185ede225d87df5fe4345f27f44a99e432

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bhashini_client-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9f1febc0df7baa055a3d6f92e80e0efb90c3a98039d3c44f1ea5436d1cee780a
MD5 a0fac35129b924859731fce73bddb23b
BLAKE2b-256 15d0a99ffd9c11f6ba4b2f6e4cf60e4e612b21b0d272ff06a23059ffbd021a8f

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