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="NbpkqMVS3CJeq2j8",
            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.2.0.tar.gz (457.8 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.2.0-cp314-cp314t-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

gradbot-0.2.0-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.2.0-cp314-cp314-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

gradbot-0.2.0-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.2.0-cp313-cp313-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

gradbot-0.2.0-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.2.0-cp312-cp312-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for gradbot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 826e720026a22114bbaa66f6e9f5d6e1fa9fb8505bdd257088a7d5a0d49ed750
MD5 51f5308c2c752af321195e3685654a58
BLAKE2b-256 d32df4b65c9ebd0a0d758f9a81c74baa4c54728993328273b057b002f4ec1dac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9c3442fd3cf047f89391912209f042981965a31b40a6beec5eeb715ffe326e15
MD5 c5acfbdf9efc998c7b997a1d838799ac
BLAKE2b-256 fb85a1a0470186dcb008fe3d4fe3388be0eedbb7873996cd8c43088800aad988

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.2.0-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.2.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e678c3454477042d01ae201fc2dea0c9eb96c05802f7d8a81af1182b1b805ab5
MD5 74c4d9270221aa1749bd1135e0617cbf
BLAKE2b-256 03c4512b3ce1a7cb10f906b547482a5923cb344a2c82caa34790e05ab5228b29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 41eeaac90b845b80313f4d7d08c72eb8f09f0512cd8be4852e12cc1855c5f5d7
MD5 f62c87718f58e2f5f727e3ba247effd5
BLAKE2b-256 b8622dd760b353a981ec091e7f0e2cb2abb9a8fb07c7cea6b331549f96984b0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 efaf6ca2dbe60de752c9f93ef8313e8618d0f155ad760bba5b6b58ef3da9cb8f
MD5 a5a6a5f080564140575be1dc2b18dc65
BLAKE2b-256 7b578408675b7f3046d045846cb58a31e6a5284ac6d05ee2f9b4ca7464e301a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e1289113cca99edcf5c340a764a0af71a0b147b746d985494f28cb0f2a9f9bf
MD5 56563bc53d45875c408d712d4d83ef6a
BLAKE2b-256 cb3194ac955958bf201666061babd52bff8aeb1f7fd373fbef33559a5f87cb6f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.2.0-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.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 42df83c2c6e344ab9d00270c96d00d31f5e8055b08feb48ae787f19d9f6a8171
MD5 dc78f0efb313612d7ed420d17446839d
BLAKE2b-256 05c1d9d765c6b0e8a6ad33a4d0cd60edc429ddc60bd997cf846b033b2307e059

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 678dfbfb5ba213ef72c65842bbbe8a8bd68a44f2511f7768afe10fbb7359eb9b
MD5 61eaf0b3618c53a3193dac086ace2f4c
BLAKE2b-256 4580820f5f8e70cd4cb57730479c979dfef80164b12c9f3c3d4011edb6761f46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c8b05ff446efbe9b5ad1dad72cf7110cfd8bb3ac6d11fa461e613365b4801e24
MD5 4f114cbd17aa77ee4e6a14a356e9efb1
BLAKE2b-256 cc55acf2dc0b866f9337b45e2cf04e90f50fc58773cc533e40985280d906440e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c4419a46615b05cb1cc25265eb371e37300a2f163fc06cf149c80d43d87648ac
MD5 6b7e56409279d78741e218034007a2ca
BLAKE2b-256 0fc72c9adc836e8926380069492088d550cb9db867b6d7ccb0ed1f91847ebe95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.2.0-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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f54b007c9d355a27c85faebc55e01d2c18911c6fc3c30212528e02ed8d570d67
MD5 7318c6b52c519cab460efade154af7e4
BLAKE2b-256 b366aa9ed9956c76ab5fd98333b4e7d6b3b50bebf18479b39988fdb804a2ff32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9bead035ec234faecec0766002f29480f0bf27d30c42293492ec29d040e65594
MD5 5b720dffdafc9edd307685d532b1c341
BLAKE2b-256 c0e899f95a8a739f114eb6a927b70da0d36e765b1ca0140ae7d04d04de41c788

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4329b64df297a4a39ce53278091add0beb11e44eee5e34e5b9d7ac570e4a487
MD5 048a579a1f1ec12cc7205e283afd9c29
BLAKE2b-256 6e18e97c794d6c11543fb57919d4d5b20afd76ee7b3c4f341534e4acb9292bb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a9c03cacffe4d8c9828d62a5a126601e0790e89a73f8f385ebe96861c354dfe
MD5 16ebe114f33012076ea050db0e4afb1f
BLAKE2b-256 f1d8e8c8319cb6ebb43b7dab5a89fcaa08d3d51836fb29da95998dc4414852b5

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