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 closes

snapshot() 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

EncodingRequirement
pcm16, linear16Mono, 16 kHz, little-endian, sent as binary frames
opuscontainer: '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

EventCarries
config_acksession_id, confirming the handshake
directiveMeasurement for the last analysis second, with speaker_id
frame_ackThe audio clock, on a tick that carried no directive
transcript_updateIncremental segments, interim then final
transcript_revisionSettled words for a closed span, replacing the streamed words in it
speaker_updateAttribution for an interval, including revisions to earlier intervals
speaker_profilesRolling per-speaker baselines and resolved identity
state_deltaA speaker's state moved against its own baseline
turn_boundaryThe floor passed between voices
barge_inA second voice came in over held speech
session_endFinal transcript and turns
warning, errorNon-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.

FieldTypeDescription
frame_msnumberOnset of the overlap on the session clock
commit_msnumberWhere the model committed the event
duration_msnumberOverlap so far, or its full length once resolved
resolvedbooleantrue 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();

On this page