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-0.1.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-0.1.0.tar.gz.
File metadata
- Download URL: onebudd-0.1.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 |
313713bb15e40d27deff08798e25dc31226643c3e9ce591d0e6eca844e35cded
|
|
| MD5 |
103865944bdc70b04e4281f2046c342c
|
|
| BLAKE2b-256 |
51e80cd5065ad00abf2f200d28a1afa5a3bf024250219481930b26edec452e9c
|
File details
Details for the file onebudd-0.1.0-py3-none-any.whl.
File metadata
- Download URL: onebudd-0.1.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 |
901d0e94cf25d9133274300aad03fa0649fc725965e0bcce814a8e63475190de
|
|
| MD5 |
eee1eeccc7e20d323a8bf87b28da807d
|
|
| BLAKE2b-256 |
ffbf70c2c90d96555377d1e806fc69bcc2256764dfd3d91867997e906425aacd
|