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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gradbot-0.1.8-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.8-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.8-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.8.tar.gz.

File metadata

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

File hashes

Hashes for gradbot-0.1.8.tar.gz
Algorithm Hash digest
SHA256 3d625b16a13e0ce2adac01da4824de7c141259d02fb65618362794e3f450fb50
MD5 c374dabab81a8f0727cc12355069423f
BLAKE2b-256 ad7a14cf697a06bbb5792030b99896e2e2f4b77a4d922e8eeefb3275c3d08ada

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3ce066a021eb5a57545d8ddc94feb1ef9e7182a31d58f64e769b2eaa052df4fa
MD5 56e552a70fac9a2dff9624f21f2702b9
BLAKE2b-256 e0756a006164c042f1708a870c364764c492e7a49be022898f21e68f3754f64a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.8-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.8-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 805c33cb9f3e2b85e632c9d4a3caf29cb3285198eced70ef57422a04808887e2
MD5 ca9a9b296b8bb6a26a66dd72ee8a389a
BLAKE2b-256 a04e77b7572a365a911de7283db17e93a43fa0d55728990da2722098c7839543

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 42bd55c19e2756766a56b9505299df9e8723628d8edd3f61b3d7c41ac87aeebd
MD5 03e2e95238bd548232e02c28f92ba110
BLAKE2b-256 3b77d41a6d63872b82510b42e62d01844eea86161e2cd11d2a3197715e6647d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e724af6ab8f9b86bd9caafb6d543daa1c17b48f88d1b507158784607849083c2
MD5 228ce13be3bc7c5e6e48ced48d9eaa94
BLAKE2b-256 8ab40d5627ca49cf5e05d76d4a193775ef349b1fe189825084b16dc9b488296c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 567186a1dfce6b2ce6fe1ec396cdd49d0d43212eba9a5465275c6a82c8dfe0b9
MD5 b0f263d951f44cbdf14e099bf92e0c26
BLAKE2b-256 4f7e99884abd384e15d53f678dd6d2e77a669cb08ece1adb042f79509bc6e714

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 768403d4cb54213c1187436bb04b511892a3c14bd1431f2c3360cb49239471b1
MD5 15f85478c8456285ee3396a86e90fcf2
BLAKE2b-256 8e8bcaea278891be54c658817331c667caf6bd71ccf23e33a97071bd7a15c828

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.8-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.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 281c709aa84ce1076524e45f7c410a2cf0efd494034f25de48efbdcec6239070
MD5 84379e89b9d558a9c0187d4e42c0e7a4
BLAKE2b-256 9645f67c0b9fd658bfbf9509475fae1a3bf2a9cea282427a3f6cc45bbfcd33b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0131ab6ef88ef16a19fd80e8b0e889d3cf4b315a198ea115fd94dca903e5831f
MD5 f95a08dd7047c9a073ee5aa195687423
BLAKE2b-256 1f738834a76f1e6ff6c0a3aa1e97bb82aa5d2581855151f4fdc2c86d636a4a1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0496aadaf189af5aed5906219cb653e8bafeb22b55d3a76693b6a437a86b4892
MD5 4889d694a9300fdd02b6a7587835c135
BLAKE2b-256 37074e00a4a042dd94a0e282afc2ca4dc366362dc6816a13f9ff7abbd632f816

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 46981bc069191bc8a23365e7c3c2fb4118bdb0cf8a086e13c47bdbcc031fa6fc
MD5 a8c2236cd868628bef9fd85ccd12744b
BLAKE2b-256 d9af88c427df792b2292eb43c9424d967cd77e8c0b6b950d3fb86d3a5ea34ca3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradbot-0.1.8-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.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5f6f5d5172622702204a915f200ab636d152d3e853c3e0747ca4456f113ba798
MD5 5152ffb4d8029361330b6fe288d8ef04
BLAKE2b-256 8ed237b0e6acb2cc1aab69b16df2cd3e4b1bf866ec083ccf01f37d50686a8326

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 417674adcab7ab38a0b1fd75cf519285d1f06d95e6d3342eb7409189ed569e66
MD5 22a6f8d526eea184907cd75824647703
BLAKE2b-256 218858633c8a012e38f13986317cf26a3349ae12c3d845b92200a634190e5cfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1450813fcc794842b670a4aea80db20ab907fa7d6a5184d2188088da0ef63e7c
MD5 f29341f737f5ac64a6c6ebbfbcac4e7e
BLAKE2b-256 a49658e7afa9dfac9b82f5f9226e7ed658c50fd2100a4c6118e0162f91eec20f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradbot-0.1.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 623d7c27653aa71c318048dc3fd37dfc8e7bfb6228987eac0bce787ab3aa2de3
MD5 811cc2920e3a6c880889cd59e66bed94
BLAKE2b-256 d6031aaa604a327ab2d306dc7aaa9893369a3275284f1f32edcfe1ddcf9cfec9

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