OneBudd STS SDK - Real-time voice AI conversations
Project description
onebudd
Python SDK for OneBudd real-time voice AI.
Installation
pip install onebudd
Quick Start
import asyncio
from onebudd import OneBuddClient
async def main():
client = OneBuddClient("pk_test_xxx")
# Set up callbacks
client.on_audio(lambda audio: play(audio))
client.on_transcript(lambda t: print(f"{t.role}: {t.text}"))
# Connect
session = await client.start_session()
print(f"Connected: {session.id}")
# Run message loop in background
asyncio.create_task(client.run())
# Send text (skips speech recognition)
await client.send_message("Hello!")
# Or send audio (PCM 16kHz mono 16-bit)
await client.send_audio(audio_bytes)
# End session
await client.end_session()
asyncio.run(main())
Configuration
client = OneBuddClient(
api_key="pk_xxx",
base_url="wss://api.onebudd.com", # WebSocket URL
auto_reconnect=True, # Auto-reconnect on disconnect
max_reconnect_attempts=5, # Max attempts
reconnect_delay_ms=1000, # Base delay (exponential backoff)
)
API Reference
Methods
| Method | Description |
|---|---|
start_session() |
Connect and start a new session |
run() |
Run the message loop (call after start_session) |
end_session() |
End the current session |
send_audio(chunk) |
Send raw PCM audio bytes |
send_audio_with_meta(chunk, seq?) |
Send audio with metadata |
send_message(text) |
Send text (bypasses STT) |
cancel(target?) |
Cancel active operations |
Callbacks
client.on_audio(handler: Callable[[bytes], None])
client.on_transcript(handler: Callable[[Transcript], None])
client.on_state_change(handler: Callable[[StateChange], None])
client.on_error(handler: Callable[[Error], None])
client.on_connected(handler: Callable[[SessionCapabilities], None])
client.on_disconnected(handler: Callable[[str], None])
Properties
| Property | Type | Description |
|---|---|---|
is_connected |
bool |
Connection status |
session_id |
str | None |
Current session ID |
capabilities |
SessionCapabilities | None |
Server capabilities |
Types
from onebudd import (
OneBuddClient,
Session,
SessionCapabilities,
Transcript,
StateChange,
Error,
)
# Transcript
@dataclass
class Transcript:
role: str # 'user' | 'assistant'
text: str
is_final: bool
# StateChange
@dataclass
class StateChange:
from_state: str
to_state: str
trigger: str
Streaming Audio from Microphone
import pyaudio
import asyncio
from onebudd import OneBuddClient
async def stream_microphone():
client = OneBuddClient("pk_xxx")
await client.start_session()
asyncio.create_task(client.run())
# Set up PyAudio
p = pyaudio.PyAudio()
stream = p.open(
format=pyaudio.paInt16,
channels=1,
rate=16000,
input=True,
frames_per_buffer=3200, # 200ms at 16kHz
)
try:
while True:
audio_chunk = stream.read(3200)
await client.send_audio(audio_chunk)
await asyncio.sleep(0.01)
finally:
stream.stop_stream()
stream.close()
p.terminate()
await client.end_session()
asyncio.run(stream_microphone())
Error Handling
def handle_error(error: Error):
print(f"Error [{error.code}]: {error.message}")
if error.fatal:
print("Connection will be closed")
client.on_error(handle_error)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
onebudd-1.0.0.tar.gz
(6.2 kB
view details)
Built Distribution
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 onebudd-1.0.0.tar.gz.
File metadata
- Download URL: onebudd-1.0.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cae97beb2ed06c3312eb2a7551386506716a7390ab66375183915963bca51d39
|
|
| MD5 |
c895aac66a177991d1efbb3b1b9084b7
|
|
| BLAKE2b-256 |
81835f5a57444c8b3b56ebdb0644b2e192181a42544f494a0c2d08406074d130
|
File details
Details for the file onebudd-1.0.0-py3-none-any.whl.
File metadata
- Download URL: onebudd-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a6d113fb6d2c79c61f675d3612e48514955869eba72c2d61abaa4f0ef70ab9a
|
|
| MD5 |
62a0d0374766659444bc5218f8be1ed8
|
|
| BLAKE2b-256 |
a3be0aa3d5ebceef258f2c9c2e59862410b6e8afcf20da8d0b60f6428ca07e4e
|