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.websocket and gradbot.routes modules provide a WebSocket handler and route setup for building voice demos.

import fastapi
import gradbot

app = fastapi.FastAPI()
cfg = gradbot.config.from_env()

gradbot.routes.setup(app, config=cfg, static_dir="static", with_voices=True)

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

gradbot.routes.setup 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.
  • 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, Ulaw

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.7.tar.gz (451.6 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.7-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.7-cp314-cp314-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.14Windows x86-64

gradbot-0.1.7-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.7-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.7-cp314-cp314-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gradbot-0.1.7-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.7-cp313-cp313-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.13Windows x86-64

gradbot-0.1.7-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.7-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.7-cp313-cp313-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gradbot-0.1.7-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.7-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.7-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.7.tar.gz.

File metadata

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

File hashes

Hashes for gradbot-0.1.7.tar.gz
Algorithm Hash digest
SHA256 8a3f0888e48a5749b754f46fc43c0186e4f1c5a750957dc375ed1cdee8337c84
MD5 2ed32f1c8f51b303cd0b52c15d7c32f5
BLAKE2b-256 3f9721aaa70e7c79f503cac61b9afa75937542deb9000e19f703a14eb5806aba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2c5bf92bcc4db3abc4cf7ddb6483931f3da5126bedd7fc744507dab5605ff045
MD5 902bc7ccc7f691c5c18732615b943a6a
BLAKE2b-256 9fd2f1d4859167f985f839faf67c288d88d784f4a7f5641f76cc04dbcd0c49ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.7-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.7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8561597ef304d6404d5c532bc7da8c4ba71a7ecf679db17c746cd7f7143adced
MD5 c3dbd40f21b0026dcc89a199ceebae1c
BLAKE2b-256 a163a9f79ee59e02c321f7ba35be50d8105b8838c9b3a90d89cf7f049a8b80bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f219d9496381eec44092de1bf45f35f9f77c2df362ec21fe09ecbcc8ac356fe8
MD5 d15cf477c39eab7be9226a23b97f5128
BLAKE2b-256 93e349b289c77472d49a37188a97d179a416eaca0f3fbeb099f2340139ad2ee9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a47baff598f53d122c506a092ccb554df462bc9325bf6e8c563bb14fc04f700
MD5 968953b03c06623f2cad303f8e3ac5dc
BLAKE2b-256 f762fd8d57999e146cfbc689e96110cf3e70c04f85c3801d0303001c2cbe6838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13c65fa04b27bab0e9c19aa14230cbdd5fc06c7996a448f91d6f3ba73dd87abc
MD5 93951ec494bf4e3e9c828124db485e2d
BLAKE2b-256 8ad9dd5485f9d8d9c48980cd5cffdc5ffe16c0870eaf821af31b039010b2ef1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 19ea9e76e6e52cf615d891d964bb9a3e6c0f587c5749d5fe4803a3dab71b7b3c
MD5 b8a30dc96c590d7f6464ec53cf6c9c7a
BLAKE2b-256 9fe20b72fc2df87dca4fb841d0d30445f9d774fd14d68610b7227096cac4ec2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.7-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.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c69a742d5e5c9f5337fbba1012b52355c10888e6bf183493e9ceaa379220e3cf
MD5 b68d462dc06314e5bc53872b1001ee5c
BLAKE2b-256 df2a223ae174c89863192abb42786e2e0fb6caf69a6611a044f0f69ac6f6509f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4d3215e4f091b140aa3de194464acc99289ba140226579e205acc4cccffdd1b9
MD5 c8ae8424d6c182feaa78c15e16342a40
BLAKE2b-256 385fc364b2548f668ea07199a98d5b0d1831359d3adc21f03692bb2a775619d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d26200d4e5c71a3c7ea47c291102c9f57dd2300511e7e3dd312210595977c36
MD5 cd0d3bc5b2a59206c1cba2736d1dcf13
BLAKE2b-256 95f2b6a3d2a4d6591c1d9e14250373f65ee9334d497dc321f696a2ba3fdfd773

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dbc33a710c7ab909cd7664a1f355629ac197278b133a3df6571ed0581cb03253
MD5 1fa855811747fcfe948837d2b227fa78
BLAKE2b-256 1add84ec103ad8d018df5c6f16d65063a035dc9a11353d6471770e563f47084f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.7-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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 99b95867f32f9592ba4ad6cc07da6dec01b024a86730cd0f2b3cbd3e86e454ef
MD5 53289a6f84ac74262a7bf7e8fb77f296
BLAKE2b-256 a24b2703e85c7f134e58fbd2f4fc669a7670336317ee56f52134035e39dbcd8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 af25a8e43ba30f83e360c454272875b9f0e8387d019e2d033a943062d1e9c810
MD5 a61731e604e32bdf6aa4958056f27ff8
BLAKE2b-256 c2320a09665cd1bb01790196a8923d5fcc33b3619f7294ef005b32cf533e3c18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 105f3bb77127a3aef1f9571f50981c89d62055e0627d2843e82713e7c9b74dba
MD5 79512501292e645cb2067cc9c6636da5
BLAKE2b-256 7576e0e48965b5655d3fb9a6ebb945dd020fd57af386466656a1cc141d5e93f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ddebfc7aaa551ed901b880cf3f64e046bff7993e177b15fa86d7c7d4a17ce23f
MD5 04fc55cc6da22396671cf0ba0e0852da
BLAKE2b-256 cdf4d97dd4b34980a91bdd48b4e8b07eb3028a73d689287eccce7d96f227ce05

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