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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

File metadata

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

File hashes

Hashes for gradbot-0.1.5.tar.gz
Algorithm Hash digest
SHA256 930cbce2bb3ea3e40d83aff171faf146db28d883f66a548945e2923b10c283e7
MD5 e1d04d372bfa70f5e8a3aed2417089aa
BLAKE2b-256 29f45098b6efffb6af716b73155aa3683f23599b11e299c47d59ab30dd8a82cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 111cfdd3b4f2a435b87bfb745f46d9f4b0614cbd18a5843082e209f709db8f5d
MD5 02412294e927cab3ce57c79b492c8661
BLAKE2b-256 28c399dccb10d129dc904c8013fe167409bb0ca9b882eea3e0d60096b1545a26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.5-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.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 60eb847c54d1e49d8bb7491e3570e58d30df06ff064d0935a5f5c12b28079ad2
MD5 02270ba0b8a024c37488003b4140ab51
BLAKE2b-256 b719febfd87f6ae73e2db8496c0c59aa2f0e6607ed9c2977c1ea377a76aba0ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 86f96a6fa33157b130f92a1d45a9d28ab3148767abecd7473dca47291dae10f8
MD5 aff8ab76a39b56931e2c820e48e498c7
BLAKE2b-256 917dce92c902f98588431ccda71b36a51b713c230a7439b4f1912c478ee07dd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 161d1f0000f5fa2ef6952b371b76082f0521f99a6afa1829c6a8004c77439846
MD5 05c8f9f797356f52b8d89c41fc3a13a3
BLAKE2b-256 6fbd63aae7478fdb4c2a23fcf1d5c0a6b041baaf84218d1585a7c2d6535731ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec57aaac1bd3ac9b9a20f49378e206f7741806df10b2be0e19c8c1ce1f4e74d6
MD5 fecfe50713d993311210b4b9d7e15040
BLAKE2b-256 7075a1bbcd3903b191debe054d013297b60469b7928f26e6e199c71668db1ac0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2959475fa3d474bcdbf3f6459fd7fb48a5ba44e47547f2fdfc99bdf478e7651d
MD5 da487c50b45fb76bf7681224aa16edec
BLAKE2b-256 68ac89ea962ef901e0e25b36766b93989c080b5e012dea6f1cd69622b2fc96a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.5-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.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a558160a9854d66bafd17a11b9cb0753189a309745b3dc182e3b6859dbc1de17
MD5 81dd5e1354fb7b76820e21192c170a8c
BLAKE2b-256 0a6d6c1c74035d7b9c4c32373685983bb02149811abf2d01691ef8d12b433215

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a27c4a4968bfc55d709404affcb7724525b6b76aecbcba717cd111667b41d34e
MD5 ae78dfa1dc3ba151d7c22a67759d2299
BLAKE2b-256 33ff9d92cca5661b5a69d60293585e66f6c11181aaebec3fd97c14f48b5d37c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 166877198f2ea591d2433aefc6742003463fabd3db758841e083c7ed4b409745
MD5 36394c55394e8bba088b8918043ee403
BLAKE2b-256 fef63d8777ec64be49d4177676154732162f7a2364a8a1c3ba0400307f07b5a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce873fd35de9127bcc5ab9bcfbb465c89072b35cf335ce32951a8cbfc9a8abd0
MD5 8d2b210f36dfa54257dbde5248e6641e
BLAKE2b-256 97ecd11f61a78377fb331142057f5317f4fefaa46300c043e9e5a1be871941c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.5-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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0059c64b6c2c8d824af2deebdbab5cc37add9923ae329fd113d4905b6b3ce16d
MD5 e38336b954512708d17ab40a161b5f4f
BLAKE2b-256 84efa146f6330652f706c263a5d1f9532f2404d1b5351fe91a6f8902a27f8bf0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f78dc90332d10d2e444fa5539d8c015f965523a99aa08e503de7bd939b14049
MD5 c07fd75d1c162d1035aa8380d82d19d8
BLAKE2b-256 ff910ff5136240fbd2a72be0ab1c2673c9622a78b0ac5bd648f243135dc5566c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c98a57bfb6a808aa05bc8b454647cba1ef971797f4396c2659b687156de1945c
MD5 45f664baeb5bcc6fcccc289055415f5f
BLAKE2b-256 60f926c7248ef9e2403a066cc130c39970c4ba277542eb9b1b2b5c8425614959

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1988ea856ecfc4592388733ed41e181d2d85c5aea87006fe2a0e08a6a6b81301
MD5 a0105ea7b611275927b1c6393c931e09
BLAKE2b-256 fae9aeeaa717dad03d2a9dcadf2c813e9f96bcecb8b0e52012e71c490838d060

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