@reaatech/voice-agent-webrtc
Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.
Browser transport for voice AI agents over a WebSocket connection, with Opus encode/decode and PCM resampling helpers. Use this as the server-side counterpart to a browser client that streams microphone audio in, and plays agent audio out.
Installation
npm install @reaatech/voice-agent-webrtc
pnpm add @reaatech/voice-agent-webrtcOpus codec (optional)
Opus encode/decode requires a native codec binding. Install one of the following only if you need Opus (raw PCM transport works without it):
pnpm add @discordjs/opus # preferred — prebuilt native addon
# or
pnpm add prism-mediaBoth are optional and loaded lazily at runtime. isOpusAvailable() returns
false when neither is installed, and encodeOpus / decodeOpus throw a clear
error pointing you here.
Feature Overview
- WebSocket transport —
WebRTCTransportmanages a browser audio session overws - Barge-in detection — energy + confidence thresholds interrupt agent playback when the caller speaks
- Opus codec —
encodeOpus/decodeOpuswith lazy-loaded native bindings - PCM utilities —
resample,convertSampleFormat,interleaveToMono,monoToInterleave,changeVolume
Quick Start
import { WebRTCTransport } from '@reaatech/voice-agent-webrtc';
const transport = new WebRTCTransport(socket, {
outputSampleRate: 48000,
outputChannels: 1,
bargeInEnabled: true,
minSpeechDuration: 200,
confidenceThreshold: 0.6,
silenceThreshold: 500,
frameDurationMs: 20,
});API Reference
WebRTCTransport
class WebRTCTransport {
constructor(socket: WebSocket, config: WebRTCTransportConfig);
}Codec & PCM helpers
import {
isOpusAvailable,
encodeOpus,
decodeOpus,
resample,
convertSampleFormat,
interleaveToMono,
monoToInterleave,
changeVolume,
} from '@reaatech/voice-agent-webrtc';| Function | Description |
|---|---|
isOpusAvailable() | true if a native Opus binding is installed |
encodeOpus(pcm, sampleRate, channels) | PCM Int16 → Opus packet |
decodeOpus(opus, sampleRate, channels) | Opus packet → PCM Int16 |
resample(pcm, fromRate, toRate) | Linear PCM resampling |
convertSampleFormat(...) | Convert between PCM sample formats |
interleaveToMono / monoToInterleave | Channel layout conversion |
changeVolume(pcm, gain) | Apply a gain multiplier |
Related Packages
- @reaatech/voice-agent-core — Pipeline, session, latency
- @reaatech/voice-agent-telephony — Twilio/Telnyx/SignalWire/Vonage transport
- @reaatech/voice-agent-simulator — Local dev runner
