Live analysis
Measure a conversation while it is happening
Send samples you hold (a microphone, a telephony bridge, a file) to
WS /v1/stream/realtime as PCM or Opus. Events come back on the same socket.
Realtime WebSocket
const session = prosody.stream.session({
encoding: 'pcm16',
sampleRate: 16_000,
source: 'microphone',
onUpdate: (s) => render(s.snapshot()),
});
await session.start(); // resolves on config_ack
session.send(pcmChunk); // Int16Array | Uint8Array | ArrayBuffer | Buffer
await session.stop(); // asks for session_end, then closessnapshot() returns the same Transcription that transcribe returns:
turns, speakers, and prosody, rebuilt from everything received so far. The
same rendering code works on both surfaces.
Audio format
| Encoding | Requirement |
|---|---|
pcm16, linear16 | Mono, 16 kHz, little-endian, sent as binary frames |
opus | container: 'ogg' or 'webm' |
The server buffers incoming chunks and analyzes them on a one-second cadence.
Pacing a file
When you replay faster than real time, wait for each analysis second to be acknowledged before you send the next chunk:
for (const chunk of chunks) {
session.send(chunk);
await session.waitForFrame();
}Events
| Event | Carries |
|---|---|
config_ack | session_id, confirming the handshake |
directive | Measurement for the last analysis second, with speaker_id |
frame_ack | The audio clock, on a tick that carried no directive |
transcript_update | Incremental segments, interim then final |
transcript_revision | Settled words for a closed span, replacing the streamed words in it |
speaker_update | Attribution for an interval, including revisions to earlier intervals |
speaker_profiles | Rolling per-speaker baselines and resolved identity |
state_delta | A speaker's state moved against its own baseline |
turn_boundary | The floor passed between voices |
barge_in | A second voice came in over held speech |
session_end | Final transcript and turns |
warning, error | Non-fatal and fatal server conditions |
speaker_update carries the model's committed lane for an analyzed interval.
LiveSession applies it to its Conversation, so snapshot() returns the
current attributed turn set.
Turn changes and barge-ins
The model commits turn boundaries and barge-ins itself, on the same 80 ms frame clock as everything else. There is no separate voice activity detector or endpointing stage.
A barge_in means a second voice came in while someone was still speaking.
It arrives twice. The first time is when the model commits it, with
resolved: false and the duration so far. The second is when the overlap
ends, with resolved: true and the full duration. Both copies carry the same
frame_ms, which points back to where the overlap began, so you can treat
frame_ms as the barge-in's id. commit_ms is where the decision landed.
| Field | Type | Description |
|---|---|---|
frame_ms | number | Onset of the overlap on the session clock |
commit_ms | number | Where the model committed the event |
duration_ms | number | Overlap so far, or its full length once resolved |
resolved | boolean | true once the overlap has ended |
A turn_boundary carries frame_ms and commit_ms. Like barge_in,
frame_ms points back to where the evidence for the boundary began.
import type { BargeInEvent } from '@prosodyai/sdk';
const bargeIns = new Map<number, BargeInEvent>();
const stream = prosody.stream.connect({
onBargeIn: (event) => bargeIns.set(event.frame_ms, event),
onTurnBoundary: (event) => markTurn(event.frame_ms),
});If you want the raw events without the conversation spine, prosody.stream.connect
hands you each event as it arrives. Build a VoiceFrame from a directive to
read the measured state, the movement, and the affect:
import { VoiceFrame } from '@prosodyai/sdk';
const stream = prosody.stream.connect(
{
onDirective: (event) => {
const frame = VoiceFrame.fromDirective(event);
log(frame.speakerId, frame.state?.intonation.pitch, frame.vad);
},
onTranscriptUpdate: (event) => log(event.segments),
},
{ encoding: 'pcm16', sampleRate: 16_000 },
);
await stream.connect();
stream.sendAudio(pcmChunk);
stream.end();