Live analysis
Stream PCM16 or Opus audio over WS /v1/stream/realtime for live turns, speakers, turn boundaries, and acoustics.
Stream audio from a microphone, media server, telephony bridge, or file into WS /v1/stream/realtime. Committed transcripts, speaker attribution, voice measurements, turn boundaries, and barge-ins stream back over the same socket.
LiveSession
prosody.stream.session() manages the WebSocket handshake, applies every incoming event to an internal Conversation, exposes snapshot() with the exact same Transcription shape returned by prosody.transcribe(), and implements AsyncIterable<ProsodyEvent> for for await loops.
import { ProsodyClient } from '@prosodyai/sdk';
const prosody = new ProsodyClient();
const session = prosody.stream.session({
encoding: 'pcm16',
sampleRate: 16_000,
source: 'microphone',
});
await session.start(); // resolves on config_ack
// Consume live events idiomatically with for-await
(async () => {
for await (const event of session) {
if (event.type === 'transcript_update') console.log(event.segments);
if (event.type === 'barge_in') console.log('Barge-in at', event.frame_ms);
}
})();
session.send(pcmChunk); // Int16Array | Uint8Array | ArrayBuffer | Buffer
const end = await session.stop();
const finalTranscript = session.snapshot();You can also pass onUpdate, onError, onClose, or onEvent callbacks to prosody.stream.session() for reactive UI state updates.
Audio formats
| Encoding | Format requirements |
|---|---|
pcm16, linear16 | Mono, 16 kHz, signed 16-bit little-endian binary frames |
opus | Set container: 'ogg' or container: 'webm' |
Selecting capabilities
Pass capabilities to run only the pipeline stages your call requires. Omitting capabilities enables all three.
const session = prosody.stream.session({
encoding: 'pcm16',
sampleRate: 16_000,
capabilities: ['transcription', 'diarization'],
});Available capabilities: transcription, diarization, acoustic_state. Omitting acoustic_state skips acoustic measurement and speaker identity state tracking.
Pacing a recorded file
When replaying a file from disk, send 80 ms frames (1,280 samples at 16 kHz) at real-time pace or wait on waitForFrame() between chunks so you do not outrun the socket's analysis window:
for (const chunk of chunks) {
session.send(chunk);
await session.waitForFrame();
}Wire events
| Event | Carries |
|---|---|
config_ack | session_id confirming the handshake and active capabilities |
directive | Acoustic measurement and affect readout for the latest interval |
frame_ack | Audio clock heartbeat on ticks without a directive |
transcript_update | Incremental interim and final segments |
transcript_revision | Settled words for a closed span, replacing earlier streamed words |
speaker_update | Committed speaker lane attribution (including retroactive revisions) |
speaker_profiles | Rolling speaker baselines and resolved durable identity |
state_delta | Significant excursion of a speaker's state against their baseline |
turn_boundary | Floor handoff between voices |
barge_in | Second voice entering over active speech |
session_end | Final transcript, turns, and timeline |
warning, error | Non-fatal diagnostic warnings and fatal errors (InsufficientCreditsError on 4002, AuthenticationError on 4001) |
Turn boundaries and barge-ins
ProsodySSM commits turn boundaries and barge-ins directly on the 80 ms acoustic clock.
A barge_in arrives twice with the same frame_ms (its onset timestamp, which acts as its identifier): first at commit with resolved: false, then when overlap ends with resolved: true and the full duration_ms.
| Field | Type | Description |
|---|---|---|
frame_ms | number | Onset of the event on the session clock |
commit_ms | number | Clock position where the model committed the decision |
duration_ms | number | Overlap length so far, or full duration once resolved |
resolved | boolean | true once the overlap has ended |
Low-level event stream
Use prosody.stream.connect() when you want parsed events directly without LiveSession:
import { ProsodyClient, VoiceFrame, type BargeInEvent } from '@prosodyai/sdk';
const prosody = new ProsodyClient();
const bargeIns = new Map<number, BargeInEvent>();
const stream = prosody.stream.connect(
{
onDirective: (event) => {
const frame = VoiceFrame.fromDirective(event);
console.log(frame.speakerId, frame.state?.intonation.pitch, frame.vad);
},
onBargeIn: (event) => bargeIns.set(event.frame_ms, event),
onTurnBoundary: (event) => console.log('Turn at', event.frame_ms),
onTranscriptUpdate: (event) => console.log(event.segments),
},
{ encoding: 'pcm16', sampleRate: 16_000 },
);
await stream.connect();
stream.sendAudio(pcmChunk);
stream.end();