Skip to main content

Bodhi Python SDK

Bodhi Python SDK provides a client for Navana's streaming speech recognition API.

Installation

pip install bodhi-sdk

Usage

To use the Bodhi Python SDK, follow these steps:

  1. Installation: Install the SDK using pip:

    pip install bodhi-sdk
    
  2. Initialization: Create a BodhiClient instance with your API key and customer ID:

    from bodhi import BodhiClient
    
    client = BodhiClient(api_key="YOUR_API_KEY", customer_id="YOUR_CUSTOMER_ID")
    
  3. Transcription: Use the client methods to transcribe audio. The SDK supports transcription from local files, remote URLs, and streams.

    • Local File Transcription:

      config = TranscriptionConfig(
        model="hi-banking-v2-8khz",
        at_start_lid=False,    # Enable language identification at start (default: False)
        transliterate=False,   # Enable transliteration output (default: False)
        endpoint_silence_duration=0.6,  # Trailing silence before an utterance
                                        # is finalised, in seconds. Omitted
                                        # unless set; server default 0.44,
                                        # clamped to 0.44-1.2
      )
      response = client.transcribe_local_file(audio_file_path, config=config)
      print(response.text)
      
    • Remote URL Transcription:

      config = TranscriptionConfig(
        model="hi-banking-v2-8khz",
        at_start_lid=False,    # Enable language identification at start (default: False)
        transliterate=False,   # Enable transliteration output (default: False)
        endpoint_silence_duration=0.6,  # Trailing silence before an utterance
                                        # is finalised, in seconds. Omitted
                                        # unless set; server default 0.44,
                                        # clamped to 0.44-1.2
      )
      response = client.transcribe_remote_url("http://example.com/audio.wav", config)
      print(response.text)
      
    • Streaming Transcription: Refer to the examples for detailed instructions on setting up streaming transcription.

  4. Event Handling: You can register event listeners to handle different stages of the transcription process using the client.on method and the LiveTranscriptionEvents enum. This is particularly useful for streaming and remote URL transcriptions where events are emitted asynchronously.

    from bodhi import LiveTranscriptionEvents
    
    async def on_transcript(response):
        print(f"Transcript: {response.text}")
    
    async def on_utterance_end(response):
        print(f"UtteranceEnd: {response}")
    
    async def on_speech_started(response):
        print(f"SpeechStarted: {response}")
    
    async def on_error(e):
        print(f"Error: {str(e)}")
    
    client.on(LiveTranscriptionEvents.Transcript, on_transcript)
    client.on(LiveTranscriptionEvents.UtteranceEnd, on_utterance_end)
    client.on(LiveTranscriptionEvents.SpeechStarted, on_speech_started)
    client.on(LiveTranscriptionEvents.Error, on_error)
    

    Common events include:

    • LiveTranscriptionEvents.Transcript: Emitted when a new transcription segment is available.
    • LiveTranscriptionEvents.UtteranceEnd: Emitted when an utterance is detected as complete.
    • LiveTranscriptionEvents.SpeechStarted: Emitted when speech activity is detected.
    • LiveTranscriptionEvents.Error: Emitted when an error occurs during transcription.
    • LiveTranscriptionEvents.Close: Emitted when the WebSocket connection is closed.

Pipecat integration

Building a voice agent with Pipecat? Bodhi drops into the STT slot of a Pipecat pipeline:

pip install "bodhi-sdk[pipecat]"
import os

from pipecat.pipeline.pipeline import Pipeline

from bodhi.integrations.pipecat_stt import BodhiHotword, BodhiSTTService

stt = BodhiSTTService(
    api_key=os.environ["BODHI_API_KEY"],
    customer_id=os.environ["BODHI_CUSTOMER_ID"],
    model="hi-general-v2-8khz",
    settings=BodhiSTTService.Settings(
        parse_number=True,                   # normalise numbers, dates, currency
        endpoint_silence_duration=0.6,       # server-side endpointing, 0.44-1.2s
        hotwords=[BodhiHotword("बजाज फिनसर्व", 2.0)],
    ),
)

pipeline = Pipeline([
    transport.input(),
    stt,
    context_aggregator.user(),
    llm,
    tts,
    transport.output(),
])

That is the whole integration — api_key, customer_id and model are the only required arguments, and url defaults to wss://bodhi.navana.ai. Bodhi's partial results arrive as InterimTranscriptionFrames and its endpointed final results as TranscriptionFrames, so interruption handling and turn taking work exactly as they do with any other Pipecat STT service.

Maintained by Navana Tech, who build Bodhi.

Written for pipecat-ai 1.4 and verified on 1.4.0 and 1.8.1. Streaming and transcripts also work as far back as 1.0.0; switching model or hotwords at runtime needs 1.4+, since that is where Pipecat's reconnect hook arrived. Needs Python 3.10+, as Pipecat does.

If you pin pipecat-ai below 1.4, install plain bodhi-sdk (so pip doesn't touch your pin) and import the same module, or copy bodhi/integrations/pipecat_stt.py into your project — it is self-contained and imports nothing else from this SDK.

Advanced features

Every field from the streaming advanced features page is reachable from here:

Bodhi feature How to set it
Context biasing (hotwords) Settings(hotwords=[BodhiHotword("phrase", 2.0)])
Endpoint silence threshold Settings(endpoint_silence_duration=0.6) — seconds; server default 0.44, clamped to 0.44–1.2
Parse numbers into numerals Settings(parse_number=True)
Partial result exclusion BodhiSTTService(..., interim_results=False) — also stops the server sending them
Aux metadata BodhiSTTService(..., aux=True)
Confidence and word timings already on every frame's result
Confidence filtering BodhiSTTService(..., min_confidence=0.5) — Pipecat's guidance; 0 keeps everything

result carries the raw Bodhi message, so word timings and confidence are there on every final without setting any flag:

segment = frame.result["segment_meta"]
segment["confidence"]        # 0.87 — utterance level
segment["words"][0]          # {"word": "आपने", "confidence": 0.873,
                             #  "start_time": 0.32, "end_time": 0.48}

aux=True adds an aux_info block on top of that, with request_time, eot_wait_time and processed_audio_duration for latency debugging.

Trying it out

Two runnable examples, neither needing an LLM or TTS key:

export BODHI_API_KEY=... BODHI_CUSTOMER_ID=...

# 1. Transcribe a recording through a real Pipecat pipeline.
python examples/pipecat_stream_wav.py examples/loan.wav --model hi-banking-v2-8khz

# 2. Transcribe your microphone live in the browser.
pip install "pipecat-ai[webrtc,silero,runner]"
python examples/pipecat_mic_bot.py     # then open http://localhost:7860/client

For a full talking bot, follow the Pipecat quickstart and replace its DeepgramSTTService(...) line with the BodhiSTTService(...) above.

docs/pipecat-listing/bodhi.mdx is this integration's service page for docs.pipecat.ai, submitted as a community integration. Keep it in step with the parameters above.

For complete code examples and detailed usage instructions for various scenarios, please refer to the official documentation.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bodhi_sdk-1.4.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

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

bodhi_sdk-1.4.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file bodhi_sdk-1.4.0.tar.gz.

File metadata

  • Download URL: bodhi_sdk-1.4.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for bodhi_sdk-1.4.0.tar.gz
Algorithm Hash digest
SHA256 c2de736035cfa1e8e082f8687025a6d5ea8ae3495a26a893e742465ef8e28368
MD5 b2538c21a83af74ef533eb26092d06ab
BLAKE2b-256 9f90abcf54386bfa75fb2614524232229f3f08a76c981791698ae7e3152828f3

See more details on using hashes here.

File details

Details for the file bodhi_sdk-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: bodhi_sdk-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for bodhi_sdk-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e5988948bab66d0b48e14cd10ef66ccb51cf722fc8cef937f92f5983ff7154a
MD5 4c53478a81751b006a7d8881637d1415
BLAKE2b-256 1b6f2c054d8867dbe6ec9168ad5dffaa6f0592411c4d6b762594eb38adbb60b2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0.post1

2 files

1.0.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page