SDK Guides
Install and use OneBudd SDKs for JavaScript, Python, and Go.
Available SDKs
JavaScript/TypeScript
Full-featured SDK for Node.js and browser with WebSocket management.
Python
Async Python SDK with callback decorators and PyAudio support.
Go
Native Go SDK with gorilla/websocket and PortAudio integration.
Installation & Usage
Installation
Terminal
npm install @onebudd/sdk
# or
yarn add @onebudd/sdk
# or
pnpm add @onebudd/sdkCore Usage
app.js
import { OneBuddClient } from '@onebudd/sdk';
const client = new OneBuddClient({
baseUrl: 'wss://api.onebudd.com',
autoReconnect: true
});
// Event handlers
client.on('audio', (audioData) => {
// Binary audio data for playback
playAudio(audioData);
});
client.on('transcript', ({ text, isFinal }) => {
console.log(isFinal ? 'Final:' : 'Interim:', text);
});
client.on('state_change', (state) => {
console.log('State:', state); // 'listening' | 'processing' | 'speaking'
});
client.on('error', ({ code, message, fatal }) => {
console.error(`Error [${code}]: ${message}`);
if (fatal) {
// Reconnect required
}
});
// Start session and send audio
await client.startSession({ auth_token: 'sk_live_xxx' });
client.sendAudio(audioBuffer);
client.sendMessage('Hello, how are you?');
client.cancel(); // Interrupt current response
await client.endSession();Browser Microphone Example
microphone.js
// Browser microphone capture
const stream = await navigator.mediaDevices.getUserMedia({
audio: { sampleRate: 16000, channelCount: 1 }
});
const audioContext = new AudioContext({ sampleRate: 16000 });
const source = audioContext.createMediaStreamSource(stream);
const processor = audioContext.createScriptProcessor(3200, 1, 1);
processor.onaudioprocess = (e) => {
const pcmData = e.inputBuffer.getChannelData(0);
const int16Data = new Int16Array(pcmData.length);
for (let i = 0; i < pcmData.length; i++) {
int16Data[i] = Math.max(-32768, Math.min(32767, pcmData[i] * 32768));
}
client.sendAudio(int16Data.buffer);
};
source.connect(processor);
processor.connect(audioContext.destination);SDK Methods
| Method | Description |
|---|---|
startSession() | Establish WebSocket connection and authenticate |
endSession() | Gracefully close the session |
sendAudio() | Send audio chunk (binary PCM data) |
sendMessage() | Send text message directly to LLM |
cancel() | Interrupt current AI response (barge-in) |
SDK Events
| Event | Description |
|---|---|
audio | Binary audio data ready for playback |
transcript | Speech-to-text result (interim or final) |
state_change | Pipeline state: listening, processing, speaking |
error | Error with code, message, and fatal flag |
connected | WebSocket connection established |
disconnected | WebSocket connection closed |