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="cLONiZ4hQ8VpQ4Sz",
            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.9.tar.gz (452.1 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.9-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.9-cp314-cp314-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.14Windows x86-64

gradbot-0.1.9-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.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gradbot-0.1.9-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.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gradbot-0.1.9-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.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

File metadata

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

File hashes

Hashes for gradbot-0.1.9.tar.gz
Algorithm Hash digest
SHA256 1eb1cff0140298ebde586c8aba0b76f63c549f3304f553258a8af80cb6b428bb
MD5 ac92254b06009ba5bd9467c924666ecb
BLAKE2b-256 cd2a97be864dfe09726b9a38fc93795417408e8250464e7c72f751bd387251c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 27c70605139ab74ebccad8fc088d6131ad66b3e50ed69a905d8d87f2d22c07f6
MD5 591c43f76658b80ba606d1468e246b15
BLAKE2b-256 7f21eef422fe501725b91ca8ef56aeb97d935159e2e0f8c89dfcce58c2adab84

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.9-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.14.1

File hashes

Hashes for gradbot-0.1.9-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b08dc94ef4cf237fabe0fe1223117923602414fd3bf2b8d72548afb179b0e672
MD5 c0a1572c70f1ff96e63f3aa37a75a160
BLAKE2b-256 7ddc283ba013edf426ee52a86492d8598aa21e497fa508ed7fee92abd3a794d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 db8f164df7e23cf4f780bd4429aefdcf5baf6ceed902a5aec5173295ca7cd929
MD5 60d6352c58ac1f54bf963267fae6f6a7
BLAKE2b-256 5b5547fb9304f0c44ce74794d4d85fded04f99e1f881bfaa4a4bd032cc832630

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09a0197571d589c112a055542b3a9aa812a77eff3c69e5449b0e8ab3e7fb5e4e
MD5 56fcd7e21b677612d3a59e4f5c25d853
BLAKE2b-256 46b3239078517d74575babd0deb5349e1d6faea230f701b093b23c5adfb3b56f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9439c1aef1a514bd853ece0b6c924de97942516e2ccaf711a8556fa1f507734
MD5 b58e027316c4ac76a7f916e5f8b84c7d
BLAKE2b-256 ad9727ff519a3075340cd212bf7b275413e395780aa9638ae227f80efe8942cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.9-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.14.1

File hashes

Hashes for gradbot-0.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1aa4ecec3efea57cbe500dd647897448250254b97d9aa131114a57e83ee5c6e0
MD5 eab442d3b956b01410d15febc096c155
BLAKE2b-256 a0d37af4ea3042a8419e887d3687e5541e76284437e8458ac55ea0d2ad130f42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6be22b32e94399d317045cd4368ba11955e96bfaec3655e28886412e09cd7d34
MD5 2e5d9db901295229159b06204b00e5f0
BLAKE2b-256 e983ea8c5acf1cd04ec6885b6e90581b54cae9b7ee9a9cc3c15bff11b537e2a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19146ccda1e176d6fa9aa87f1c374e0f9ee3fcd19ad042f3d6b382409b06f724
MD5 3c58cbbf0db6d02ec56a421c5ac51bac
BLAKE2b-256 e2346e76066a7c0141382b9822d3aa2526a3f4ff2ca91334e214c5951689a1ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 30f290a90ba88c7acee30ecf62bd2abc57dcdb76228f2396f4ba6bb70895d886
MD5 9b365c3359aeccf32209f60105179d8c
BLAKE2b-256 3f729babe2f26fe9e70cd59744b490c5c0760d6d6063f2cefbce2eb83ed32a35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.9-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.14.1

File hashes

Hashes for gradbot-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7eedf4b43d5266db36b6e8fc90b865376cee269079a5bf8850e2b0ae48da437c
MD5 09695856462107782e2f59967cadcb5c
BLAKE2b-256 22340d4efc830da731b96c1973bced7c96fa8714942a0279eb82244e00f86608

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 40371d490439d2a9a7c26d9c724c7a1a3d8bc005a24b3fcb7e6e349080aba4ed
MD5 954466634f5853537b25260d078b8421
BLAKE2b-256 533e8ab4e693f1f52fabae9e83ba7502cdc68824692c9951a55402acea21494d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ade1553120083114d3cccae0c915bd272b7725c5c738f5d706fba5c2f42f42a9
MD5 08bbcdc851cd1d89cdd0b88c0d873beb
BLAKE2b-256 acad6c87470fb4ef1dc3563f2f6d0578d6f79e7c55d0a9149144ae9e80691d06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 465398f9bc4fd43eaf78ea234a73b61944b88703610b55fb1b383a11bb72183b
MD5 982317cab5e921bbc9cca0280aa2d267
BLAKE2b-256 3a1aa742c144029df8d3100ec8a552c4686e1309df120b724f7ebe62bfc3dd9e

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