Skip to main content

Python bindings for gradbot voice AI library

Project description

gradbot

Python bindings for the gradbot voice AI library. Real-time speech-to-speech with tool calling.

Installation

pip install gradbot

Environment Variables

Variable Required Description
GRADIUM_API_KEY Yes API key for Gradium STT/TTS services
LLM_API_KEY Yes API key for OpenAI-compatible LLM
LLM_BASE_URL No LLM API base URL (defaults to OpenAI)
LLM_MODEL No LLM model name (auto-detected if only one available)
GRADIUM_BASE_URL No Base URL for Gradium services

Quick Start

import asyncio
import gradbot

async def main():
    input_handle, output_handle = await gradbot.run(
        session_config=gradbot.SessionConfig(
            voice_id="YTpq7expH9539ERJ",
            instructions="You are a helpful assistant.",
            language=gradbot.Lang.En,
        ),
        input_format=gradbot.AudioFormat.OggOpus,
        output_format=gradbot.AudioFormat.OggOpus,
    )

    while True:
        msg = await output_handle.receive()
        if msg is None:
            break
        if msg.msg_type == "audio":
            play(msg.data)  # bytes
        elif msg.msg_type == "tool_call":
            result = handle(msg.tool_call.tool_name, msg.tool_call.args_json)
            await msg.tool_call_handle.send(result)

asyncio.run(main())

Remote Mode

Connect to a gradbot_server instead of running STT/LLM/TTS locally:

input_handle, output_handle = await gradbot.run(
    gradbot_url="wss://your-server.com/ws",
    gradbot_api_key="grd_...",
    session_config=config,
    input_format=gradbot.AudioFormat.OggOpus,
    output_format=gradbot.AudioFormat.OggOpus,
)

When gradbot_url is set, all other client params are ignored. The server handles everything.

FastAPI Integration

The gradbot.fastapi module provides a WebSocket handler and route setup for building voice demos.

from fastapi import FastAPI, WebSocket
from gradbot.fastapi import websocket_chat_handler, setup_demo_routes

app = FastAPI()

setup_demo_routes(app, static_dir="static", voices=True)

@app.websocket("/ws")
async def ws(websocket: WebSocket):
    await websocket_chat_handler(
        websocket,
        on_start=lambda msg: gradbot.SessionConfig(
            instructions="You are a helpful assistant.",
        ),
    )

setup_demo_routes registers /api/audio-config, serves your static files, and automatically serves the bundled JS audio processor at /static/js/.

WebSocket Protocol

Direction Format Description
Client → Server JSON {"type": "start", ...} Begin session
Client → Server Binary Audio data
Client → Server JSON {"type": "config", ...} Reconfigure mid-session
Client → Server JSON {"type": "stop"} End session
Server → Client JSON Transcripts, events, audio timing
Server → Client Binary Audio data

API Reference

Functions

  • run(...): Create clients and start a session. Returns (SessionInputHandle, SessionOutputHandle).
  • create_clients(...): Create reusable GradbotClients for multiple sessions.
  • flagship_voices(): List all available voices.
  • flagship_voice(name): Look up a voice by name (case-insensitive).
  • voices_json(): All voices as JSON-serializable dicts.
  • voice_switching_tools(): ToolDef list for switch_to_{name} tools.
  • resolve_voice_from_tool(tool_name): Resolve a switch_to_* tool name to a FlagshipVoice.
  • init_logging(): Initialize debug logging.

Enums

Enum Values
Lang En, Fr, Es, De, Pt
Gender Masculine, Feminine
Country Us, Gb, Fr, De, Mx, Es, Br
AudioFormat OggOpus, Pcm (24kHz in / 48kHz out), Ulaw (G.711 mu-law)

Classes

  • SessionConfig: voice_id, instructions, language, assistant_speaks_first, silence_timeout_s, tools
  • ToolDef: name, description, parameters_json
  • SessionInputHandle: send_audio(bytes), send_config(SessionConfig), close()
  • SessionOutputHandle: receive() -> MsgOut | None
  • MsgOut: msg_type is one of "audio", "tts_text", "stt_text", "event", "tool_call"
  • ToolCallInfo: call_id, tool_name, args_json
  • ToolCallHandlePy: send(result_json), send_error(error_message)

Examples

See demos/ for complete examples including tool calling, voice switching, and WebSocket frontends.

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

gradbot-0.1.4.tar.gz (451.7 kB view details)

Uploaded Source

Built Distributions

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

gradbot-0.1.4-cp314-cp314t-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

gradbot-0.1.4-cp314-cp314-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.14Windows x86-64

gradbot-0.1.4-cp314-cp314-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

gradbot-0.1.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gradbot-0.1.4-cp314-cp314-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gradbot-0.1.4-cp313-cp313t-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ x86-64

gradbot-0.1.4-cp313-cp313-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.13Windows x86-64

gradbot-0.1.4-cp313-cp313-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

gradbot-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gradbot-0.1.4-cp313-cp313-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gradbot-0.1.4-cp312-cp312-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.12Windows x86-64

gradbot-0.1.4-cp312-cp312-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

gradbot-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gradbot-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file gradbot-0.1.4.tar.gz.

File metadata

  • Download URL: gradbot-0.1.4.tar.gz
  • Upload date:
  • Size: 451.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for gradbot-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f200e27467fe0bf7c0d53de3bffcbea461c94ea951ffda2c42af2a2c186ab4b1
MD5 8ee8d423c395a21100739effd31d23c9
BLAKE2b-256 2014ef6efe2952fc8adb50a641701e15bd0f7fe4787135e9e73d093c2bc09416

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7b6b4b8e62e6e9f2e26d9bc4e17b1e338a27381e1060e8194c7d3057f7865cb1
MD5 f6dd970914ff162e640ed28839631ae8
BLAKE2b-256 c504a5723f88c7b162f8e47778434715184635e7b1b8f5fb0d207504ff787300

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: gradbot-0.1.4-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for gradbot-0.1.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b69274d4eb2bc42399ba5b3cb58fca75d42669db41e0c378da1ad3236f3ae824
MD5 da987080b79c750f45860bacbf84a411
BLAKE2b-256 1d9495bb682973836c95fb4dfc7ccbdf97fe33b27b18ada66c195c9c420a58d7

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aff8ea5dc96084d19c017a7c19a2fcaf79931f1dc5e64db3e2072e3802e322cb
MD5 5dcb36459f01e2fb40e3850383bb08fa
BLAKE2b-256 3c52b7faa1f3a5fe2d55e10d8971faa3be76702dc850a171b142622909b48e63

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eaf39f96b42a786ee61ab14eedb74afd819ea04b725916195f9dc75a3f1ceeb0
MD5 555df1eb08e361522ef6e5dc83a036af
BLAKE2b-256 496718201da7bb88dacc077eaf4cb20abcc8fb751c92609fa84e16c8dc06e3da

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 04b1f90304788bbb9e84eac776ee7d0832d64241f9c5f85cde9ce3ba9cb7c1f5
MD5 acd2c050548e9133bbe0309db889394d
BLAKE2b-256 1bfe5e1d82509cec760c31d21dc9d38ef05c4f1541f5820338903209660c14b0

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp313-cp313t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b84a294ec804181a98c0591b6a8b175c758075fdf856e367dde6de6e27625c67
MD5 478bad968f8a722e2a677403f6b4951a
BLAKE2b-256 f4207a72da074490fd0d6239e46d6783d81146e24da1f623db1fa6045dfff2aa

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gradbot-0.1.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for gradbot-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7b56529e3b9bbbb2e52ad153436ac8a511f0764d7f02e5e6c4453fa397c7a4e3
MD5 75a5c1f83e657e0655942eb709896074
BLAKE2b-256 ec7ec8369c2ee6a918ba4b272d10652d8ab66d5870f5aa2eb58a7caf9449cde3

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6d3c492a2c5ba03d111e4252813547070ae5517eff0414cb33d64d50099ec886
MD5 b83c81a4a293f35822c26d8c4b5d09bc
BLAKE2b-256 c6df521d8238520841797978d33d43f8984c2525d3bc585eca60fb5c47416438

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c0a27c12b48753987bc45fc28ef454a18d8dc964677c2c5990028fbcae346fc
MD5 b525868e01c73b3199b3ba7aebd87204
BLAKE2b-256 39966eff2f8cb2199c5480030bddab3bc98ab1bc05afb1900ea4dccf26ac2243

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5146aa420a763afd79f8d52985e3a39cc5fcc9d0fb5eefa9189fa2a3661d1daf
MD5 c21d3848f45d0d222e5c494efdfa0812
BLAKE2b-256 e1a67bf1716c248d22f8b721ef4c58e5a6ac5e152c2b97fb866a420faf36b228

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gradbot-0.1.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for gradbot-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6988c222d149ab2eabfef7a2a458e92c01b908f50987aa40eb051642abd07dec
MD5 9f8c4f8dcc347cdf0cd4ce3cb3ea5f00
BLAKE2b-256 719681c288bf33091a5fc1deff842b847d262d503e01b76e11e9196881aa55be

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a9ca93f9acac53a05bbc923a837149522513bc3a40edaeb3882e3db61cb86028
MD5 d4d7586e5ddf17874d65edb5c5d43ae2
BLAKE2b-256 a3268fa663db056d1184434ebd8a1c39abee0e20ee141f367da2cf1964b9056a

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f9acd1a3b53f17f13a923aa4e790ce71cc3af12900f9b3494e36e7c0cb1919ba
MD5 b335f2cf7c7364f47a5d9c4bedd2bcc5
BLAKE2b-256 71e25dc32194724aa0d8b6db6e05e0635db07789079372a647605db9bdfaaf00

See more details on using hashes here.

File details

Details for the file gradbot-0.1.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gradbot-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6f78d29e561d749de2aed7bbfefa60d2636a23dc06ffc981d79038c9082e4d8
MD5 35fbd8e0e8208e7232137295a722b65d
BLAKE2b-256 2aa80c48ceda9cde149b63d1727506a3c7adbd0d6582db54196898713d45a4d2

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