Python bindings for gradbot voice AI library
Project description
gradbot
Python bindings for the gradbot voice AI library.
Installation
Build and install in development mode:
cd gradbot_py
maturin develop
Or build a wheel:
maturin build --release
pip install target/wheels/gradbot-*.whl
Quick Start
import asyncio
import gradbot
# Initialize logging (optional)
gradbot.init_logging()
async def main():
# Create session with default settings
input_handle, output_handle = await gradbot.run(
session_config=gradbot.SessionConfig(
voice_id="YTpq7expH9539ERJ", # Emma voice
instructions="You are a helpful assistant.",
language=gradbot.Lang.En,
),
input_format=gradbot.AudioFormat.OggOpus,
output_format=gradbot.AudioFormat.OggOpus,
)
# Send audio and receive responses
# ... your audio handling code ...
asyncio.run(main())
Environment Variables
GRADIUM_API_KEY- API key for Gradium STT/TTS services (required)GRADIUM_BASE_URL- Base URL for Gradium services (optional)LLM_API_KEY- API key for OpenAI-compatible LLM API (required)LLM_BASE_URL- Base URL for LLM API (optional, defaults to OpenAI)LLM_MODEL- LLM model name (optional, auto-detected if single model available)
API Reference
Functions
init_logging()
Initialize tracing subscriber for debug logging. Call once at startup.
flagship_voices() -> list[FlagshipVoice]
Returns all available flagship voices.
for voice in gradbot.flagship_voices():
print(f"{voice.name}: {voice.voice_id} ({voice.language})")
flagship_voice(name: str) -> FlagshipVoice
Look up a flagship voice by name (case-insensitive).
voice = gradbot.flagship_voice("emma")
print(voice.voice_id) # "YTpq7expH9539ERJ"
create_clients(...) -> GradbotClients
Create reusable clients for multiple sessions.
clients = await gradbot.create_clients(
gradium_api_key="...", # or use GRADIUM_API_KEY env var
llm_base_url="https://api.openai.com/v1",
)
run(...) -> tuple[SessionInputHandle, SessionOutputHandle]
Create clients and start a session in one call.
input_handle, output_handle = await gradbot.run(
session_config=config,
input_format=gradbot.AudioFormat.OggOpus,
output_format=gradbot.AudioFormat.OggOpus,
)
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 (gradium_api_key, llm_*, etc.) are ignored — the server handles STT/LLM/TTS. The returned handles behave identically to local mode.
Classes
Lang
Language enum: En, Fr, Es, De, Pt
Gender
Voice gender: Masculine, Feminine
Country
Voice country/accent: Us, Gb, Fr, De, Mx, Es, Br
AudioFormat
Audio encoding format:
OggOpus- Ogg container with Opus codecPcm- Raw PCM (24kHz input, 48kHz output)Ulaw- G.711 mu-law (for telephony)
SessionConfig
Session configuration:
config = gradbot.SessionConfig(
voice_id="YTpq7expH9539ERJ", # Voice ID or None for default
instructions="Be helpful.", # System prompt
language=gradbot.Lang.En, # Language
assistant_speaks_first=True, # Start with greeting
silence_timeout_s=5.0, # Silence before prompting
tools=[...], # Tool definitions for LLM
)
ToolDef
Tool definition for LLM function calling:
tool = gradbot.ToolDef(
name="get_weather",
description="Get current weather for a location",
parameters_json='{"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}'
)
SessionInputHandle
Handle for sending input to a session:
await send_audio(data: bytes)- Send encoded audioawait send_config(config: SessionConfig)- Update configurationawait close()- Close the input handle
SessionOutputHandle
Handle for receiving output from a session:
await receive() -> MsgOut | None- Get next message (None when session ends)
MsgOut
Output message with type-specific fields:
msg = await output_handle.receive()
if msg is None:
print("Session ended")
elif msg.msg_type == "audio":
# msg.data: bytes, msg.start_s: float, msg.stop_s: float
send_to_speaker(msg.data)
elif msg.msg_type == "tts_text":
# msg.text: str, msg.start_s: float, msg.stop_s: float
display_caption(msg.text)
elif msg.msg_type == "stt_text":
# msg.text: str, msg.start_s: float
display_transcription(msg.text)
elif msg.msg_type == "event":
# msg.event: Event, msg.time_s: float
handle_event(msg.event)
elif msg.msg_type == "tool_call":
# msg.tool_call: ToolCallInfo, msg.tool_call_handle: ToolCallHandle
result = await process_tool(msg.tool_call)
await msg.tool_call_handle.send(json.dumps(result))
ToolCallInfo
Tool call information:
call_id: str- Unique call IDtool_name: str- Name of the toolargs_json: str- JSON string of arguments
ToolCallHandlePy
Handle for responding to tool calls:
await send(result_json: str)- Send success resultawait send_error(error_message: str)- Send error result
Example: Voice Chat with Tools
See demos/fantasy_shop/main.py for a complete example using FastAPI, WebSockets, and tool calling.
import asyncio
import json
import gradbot
async def handle_session(websocket):
# Define tools
tools = [
gradbot.ToolDef(
name="get_time",
description="Get the current time",
parameters_json='{"type": "object", "properties": {}, "required": []}'
)
]
# Start session
config = gradbot.SessionConfig(
instructions="You are a helpful assistant with access to tools.",
tools=tools,
)
input_handle, output_handle = await gradbot.run(
session_config=config,
input_format=gradbot.AudioFormat.OggOpus,
output_format=gradbot.AudioFormat.OggOpus,
)
# Process messages
async def process_output():
while True:
msg = await output_handle.receive()
if msg is None:
break
if msg.msg_type == "audio":
await websocket.send_bytes(msg.data)
elif msg.msg_type == "tool_call":
if msg.tool_call.tool_name == "get_time":
import datetime
result = {"time": datetime.datetime.now().isoformat()}
await msg.tool_call_handle.send(json.dumps(result))
async def receive_audio():
async for data in websocket.iter_bytes():
await input_handle.send_audio(data)
await asyncio.gather(process_output(), receive_audio())
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gradbot-0.1.2.tar.gz.
File metadata
- Download URL: gradbot-0.1.2.tar.gz
- Upload date:
- Size: 111.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e51fb128d215154d8061f3a9351097ab8921cd5359746c12c5dadf4f7ab3331a
|
|
| MD5 |
98a60030eb7f13d5ceb300ce1d1354ce
|
|
| BLAKE2b-256 |
27b0b37d489d6deea39e7bf934aa2b8175b2c87415bc277ad20fb6acb7eacdde
|
File details
Details for the file gradbot-0.1.2-cp314-cp314t-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp314-cp314t-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.14t, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c50ae2d7e6cc2a2cf8d746a57456366934711c661ffbeb3070446577d9f67229
|
|
| MD5 |
b348177ebcba5347908baa5c0e9fe100
|
|
| BLAKE2b-256 |
3049d167e510aab4715a1efa83edddd127100199c2ccbe6635cf28e29ab394d5
|
File details
Details for the file gradbot-0.1.2-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3aa1d12c65bd9396ef74771f50919a3aa47d2d971a0ac8a0bacd5926cc6f6fe
|
|
| MD5 |
d42ae7ff6a956ddabde7b29732f36b39
|
|
| BLAKE2b-256 |
40e339005843ca6a12419decb4d508c269cef6fe6bf2ec72ea2f6da172d5f054
|
File details
Details for the file gradbot-0.1.2-cp314-cp314-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp314-cp314-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3961c49fa306f2e8f31b4c74fd3cfedff064f97abf3e878865a1edb815344d8f
|
|
| MD5 |
35f7a00d96e3b53d6854d299ee089c29
|
|
| BLAKE2b-256 |
28af6656ae31b99fc5ba6e27f0948d71294265514247d1f1301172ef6e25644f
|
File details
Details for the file gradbot-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3985d1b3643dfc820db615b0e785eb899e66ddd8a675c9af5469c5c9cfab6670
|
|
| MD5 |
70740c1a20ddfeaeffb161a45462c7bb
|
|
| BLAKE2b-256 |
a51e4da953a9cea30466abdffe476a778ddd3db3856d37e9aac3b46ac1781a98
|
File details
Details for the file gradbot-0.1.2-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e589899687749a063a81051aca1e81eb427899733a79e888a2d2daf01276233e
|
|
| MD5 |
3c6d80b6c95a23e2a997bff4e431cd0a
|
|
| BLAKE2b-256 |
de060484407a2d17793bd63162891b433513941e55d2e8c0b4d2742ee0e90e62
|
File details
Details for the file gradbot-0.1.2-cp313-cp313t-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp313-cp313t-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.13t, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23f8552c5066ada8a75742069cb30565dd6df78a0a45432f1e801c81dc4c31cd
|
|
| MD5 |
be626775631e3435d88181703c496eee
|
|
| BLAKE2b-256 |
9d7ba3efbf08b159a5fe4057e1b9fd8eb3acc3ce94a43f6ce5886a104db5c804
|
File details
Details for the file gradbot-0.1.2-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7085633526fedb4842f0c030e9e5592764ee7ffa73c59b8a872979a0e0e6597
|
|
| MD5 |
c5e26d0bfee6f40c633ef910e236249a
|
|
| BLAKE2b-256 |
d62cc57e2c0d9d7f68b8969268a57570980d9fecc2c7b6998adad8ded5f1af2f
|
File details
Details for the file gradbot-0.1.2-cp313-cp313-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f14fcb9f194bc058975cbfcb10b4159faa7fc9a81120d40692a09f4c9231fb8
|
|
| MD5 |
2ae31f9e2677b0744d8ec256360eb247
|
|
| BLAKE2b-256 |
f66c437dd00eee92e625d76db730addd07c148ec427df16ed40fae9bc099ea8d
|
File details
Details for the file gradbot-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a156b14e4e6d55c9c0ca39f8945f5d0709e7d788f6e8ce2c5ceb168194806b31
|
|
| MD5 |
81768cb055236c003dc169c6d3ab3056
|
|
| BLAKE2b-256 |
5f745a4ba509f106e60b51d21dce7824cdc6a11cc0e30dd6bbd26eb8e8880952
|
File details
Details for the file gradbot-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b958c97dec6caf30c761112e8ed6eeb480fc72ca8c879f6ff02bd4c59d1ff09
|
|
| MD5 |
4d60cc43a07443a3f9275f26bcd2dcb2
|
|
| BLAKE2b-256 |
b9fc519c9167c7350179bae03e0daf4ed39adba901137e4473b2523796434c5b
|
File details
Details for the file gradbot-0.1.2-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2848c050b37e58c470daccd3f6f97c3043ed0fc2ab443f10f5da0ba473b102c
|
|
| MD5 |
8f8fe6112b7ef19ba9ccab1b0814e399
|
|
| BLAKE2b-256 |
fcdefeffcb2df1caa6fcad8eb88d08102ec990da9eb719d3613269b5c62c86af
|
File details
Details for the file gradbot-0.1.2-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c41e056b182266d8ef1aa9eee9cc35ebcb72f188b5822d5d3485f09eed17c22
|
|
| MD5 |
e304d234fa5909c2275da38d0acd06e8
|
|
| BLAKE2b-256 |
100824de9c1a55ab61d7c2a130e618d4167f87821c5a2ffe79824d6dc27da239
|
File details
Details for the file gradbot-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d14c64650e97ff724625313d43a65f7918d73b6812487ec51d8e0a12d04e612c
|
|
| MD5 |
4dff1dd7f85ba7830774c10195f95a0d
|
|
| BLAKE2b-256 |
6f41e7b82831716c105e79039e92921de5ca443d3476eda5848f427cf867666b
|
File details
Details for the file gradbot-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: gradbot-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf9b3dc4b7e22ad2596efeda806f03379730b0398fdec1ea7b76292fa5e99431
|
|
| MD5 |
a4b609135450c58eb199f63287093797
|
|
| BLAKE2b-256 |
b39f079484768b5a026ebd3633bb0aae16affeed6946bcf35db6c6fa4ada3103
|