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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

File metadata

  • Download URL: gradbot-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 a518c5d776ff4ae451efb0579eeb616dc93d50fcf07ac6474fb9a21bc0a32453
MD5 96d57b05621282ce591fa0b71eca9b6a
BLAKE2b-256 3439c358eb8b39be0fd1065a8115b48bd280afabd3bcf909e7a85ff358fbc5b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bde59c5651ba394c364c09a675385c301ad5d27cbed91eb84b7e8e6fb770e286
MD5 20c896174c2e2751fdf97dbbbfecf3e5
BLAKE2b-256 659edbfc4fc8c5448f638e91fd552f0617da196bc6c1ed9cbee13ff352c7503a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.6-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.6-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 aa387c129f4640bcb3a3bf172de14006e42c87620a23ac7c3462163bf6ed4e3a
MD5 917ab1bed2dd3a71c625814d26531951
BLAKE2b-256 fe60c8805dae1c485ea0667c500edcedb3c6eb6aa314d86d294249caef48021d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b08523d1c00fc682de0a4f5719573584c554de8de83c0c6c15bbd2385a0cc82e
MD5 9ad1d2dc32409aaa93e7c536a932ff4b
BLAKE2b-256 21e9f1281bc02b43d0cffdcb49ad3007ded92094e9be91b0662a68fad12cc737

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0662dd26071a90e7267e1c8f5b7a3ce1b6f58fc71bbfbcf202de8c8fd161f4c3
MD5 774cec64eb2a5ab1f5419af128d3a7d9
BLAKE2b-256 0c424dd0592ef951b4127c7890d5b68485d331768aff6fe36cb74cbc34afa4a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5799245640f9f4bb0c7b2e5c4d723c66d04153d7a9432950564a0e231dbfc6d
MD5 7f0e21f35abd916fe98be64f1ea2192f
BLAKE2b-256 ecd464f043dbeab670233fbdb051fb325c26a68670dffadfb26113ee69d312cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e064eef3f71ec2e1631283bd8d8018455d99771d3e181c14c27674e22e95db1d
MD5 415f71a304049a1d696b0875d85fedaa
BLAKE2b-256 2caf40262fd061a66afbaa3f68d2a3f67f62c2f1ab8c5830bd86b707393b8b2a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.6-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.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7b0bab93697befcc7e19f2c88162fed65aabc942c7f433ca284670ea77d953be
MD5 e1ff084b8e79c298c7b44d74244f8d5f
BLAKE2b-256 4ee786f4b7ecccf1f08656c6e2846495dac27d30322236d698feee77130edc32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e45134d4855f121cc8ecd1002a52c05e92674b074fa617c1582668eec96df5e7
MD5 3175d4284f5f021560a7ac12d35c7867
BLAKE2b-256 a279c54af890e5141d7a6becd9c2cf346b1d3d554d9c81c48c9358530baace78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 629c41b21138ef81e039a7f6ba288b6189aff4eb2c8b644f1497ad7cb168732c
MD5 3cbdb314c24409d2b5f015aec98dca33
BLAKE2b-256 6fab72f66f6536b40bfd0a9f0bfe82946b2a4538929c77f743b7f91bf589a72a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f96e9db2bbffab69f2c245c9e0d2ac180cb827bd87130a5bfa6bc6778a9faa5
MD5 213491f66104bbdf659d69875e6f741d
BLAKE2b-256 96eb2cc39ed8f39cbdca14937e8fc79b70eecc11896ee212b7381e40d17c7683

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.6-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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 323988643d1f35d9b7753d3b2967f38e1f20a6d136ee313bb6debeba71b1350f
MD5 5240a535b6d9c553bbcfbeeead2cc096
BLAKE2b-256 dc58b134dd87e4e26017eacb04fe77728bd26ca6675ef83ba778bea266e0b433

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3ee22bb9118aa6e7ba544cf6249c64b1b1fe50d679e2e51709fbb20173554637
MD5 8e9c46271fa747b1d22272277f63b3ec
BLAKE2b-256 c17dbb982444dbc5fb6afabe7369923748594ed2f9651d20d810b1eee204d2f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f1bdf3e6a98e118df32ff4af07579a740f7c98e39a55116d65cea0e2063a0dc
MD5 c63ff8aa690a2ec8612f8c4545f49507
BLAKE2b-256 aadab8b3b9af08611d3d02e4b72831a46647f6b865e7571d6716426a9139d8b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 14609fa886f6baab89c092fcc98be21ce6cd7668b507e2c8c8f81ff3b181d72e
MD5 ffb02177cd3133a811a0eb10e9aafb3c
BLAKE2b-256 a253cbbcc7067668c58b3c9a54da3a7586aec8bf3b1e817d8ee725f203c8bdf5

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