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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

File metadata

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

File hashes

Hashes for gradbot-0.1.10.tar.gz
Algorithm Hash digest
SHA256 0a14f9c18b03f48289230e4951c0a6ce1bb8f276bf0059b8e77a54f51d4ff2f0
MD5 db91e1de3a67d7619e5a7d04455da0f5
BLAKE2b-256 7aa7e5098c751632924397b589ca46143fb3d8b9ce29214f34b9d8b4e7fbc584

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c528057f3eb6ebd776ba1e936af8afc681634328a1f10883738b6fe356003bdf
MD5 7822cfb1be93988faf030c30ae28b6f9
BLAKE2b-256 d12c0840ba30d0b8730c4595aa40863d873101b93e59bd15c4765f3352a6d0f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e4a93f4c8aadc6b6fbef42f2ab965b401dd5686468cbcf549d73301a1a019531
MD5 5e87a47bb29ebbd742d63074faca3682
BLAKE2b-256 fdfc2767f3d529513a9925bb374768984cce216e4b25d285b93ed26c44590a86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1ee95f7739a9bca686758e1744319f5af687f51da728ab57745ee6912b68080c
MD5 4d5b1ba607c2fec152c5931bc0dd25f7
BLAKE2b-256 079e815bc4b1a1a96b387a416b8dd36e031ed9f7d3d2297ab75b7f809357a93f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5a082e5c7a71f72a9d4ff30186dbbecd55182bef60dc0c6496564cc90f3e947
MD5 1ea20f38395dafe9a28dd11538f6d64c
BLAKE2b-256 5dfb043a80aebd95c609cc1721ddd3c42ef3354beb2fb7eeb11fe3fee86b261b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3555602aa60b9087fd7f4ad36b8eb844dd933c7ac0ddb0f784ca2b2b5a886980
MD5 c37e33a7ba0561a8fefa8ce91227c4a4
BLAKE2b-256 429022e4e294c644bcba4312c39058a127e8da6ed27bdf2639b609da53bc7239

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8923c197aa779da63054790110ace715d5ba2c7f10c2e44505f4b36990ace9f9
MD5 467a20e0476876fc7c554c364278f8bc
BLAKE2b-256 caf98b81272db0205fb27db7d3451d6e813b055fbcccdcfb1e996e39f68e831b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d84b4c606f734e8d7ead5b54612f77fedafb0b2717076628efabda2ecf157dd8
MD5 8d75c01d022f5f0aa2bdde32115ceff2
BLAKE2b-256 6662328206594ee7440d13bc8633a2a6b6da66d4b1572f99a93812ab261bbcfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e092b635fc18095803ead34fbe7e17da479523df182b85962ca3b00c1e3c837
MD5 8d386805b7adc6f4cfc8380cff74bff9
BLAKE2b-256 93bbfe34aaa20e5ecf907b49cf9785c31d0da03610c4d0a52127fe164531bdf1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0196feb552af46871391dc0e991c0402af382680f11f3bf0e3076ed9ef67e851
MD5 72f1ef76289de2ad77bb3455d9d5cb55
BLAKE2b-256 28d715150fb3a8f749c83ef81986d855ed58d05f235a40aab6d8d24d7b0deb8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 aca63938bff54d0283b62265da96d6df7b8686763838516473e643e75e9184e9
MD5 12a4a22351b7fc19d2243909be5f29c9
BLAKE2b-256 07ee7a18f04546b3c6f4b03bc18d4dad1cf2f466768405d45a024a5f58098d4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 399fa98d55f20e9baf50aff8139447dfeec9a11d1f06666f2b99839cdb0a4960
MD5 6c0faaa7d4a7ac2fc47aaf79cbed78ef
BLAKE2b-256 fe044f0088ba3a9440acc5ae9bdcd9a65bac4084f2a0e320a972a5b8d987dd5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e391b751d3c6cb8404d6c4b14dd9eefa6144aeae0a6464923ec2419766481913
MD5 e15e5c5a22d67b5de6750de5ab56b190
BLAKE2b-256 31ec277d6739a9c607f9a491fc27010927a18a881667dab1402eb1ba32b9604d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5e79f349a7320821f0a24d7e9c67bbfa1cd8124875599a650195113641452e1
MD5 51eea1f514c3ea62b0dbe83b0966eee1
BLAKE2b-256 f5b13de05501877d31a2c4656731ad1eaa696ad581e56ac01a89ee43eafd20ca

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