Live analysis

Stream PCM16 or Opus audio over WS /v1/stream/realtime for live turns, speakers, turn boundaries, and acoustics.

WS/v1/stream/realtimeFull-duplex analysis socket

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

EncodingFormat requirements
pcm16, linear16Mono, 16 kHz, signed 16-bit little-endian binary frames
opusSet 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

EventCarries
config_acksession_id confirming the handshake and active capabilities
directiveAcoustic measurement and affect readout for the latest interval
frame_ackAudio clock heartbeat on ticks without a directive
transcript_updateIncremental interim and final segments
transcript_revisionSettled words for a closed span, replacing earlier streamed words
speaker_updateCommitted speaker lane attribution (including retroactive revisions)
speaker_profilesRolling speaker baselines and resolved durable identity
state_deltaSignificant excursion of a speaker's state against their baseline
turn_boundaryFloor handoff between voices
barge_inSecond voice entering over active speech
session_endFinal transcript, turns, and timeline
warning, errorNon-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.

FieldTypeDescription
frame_msnumberOnset of the event on the session clock
commit_msnumberClock position where the model committed the decision
duration_msnumberOverlap length so far, or full duration once resolved
resolvedbooleantrue 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();

On this page