Reference

LiveSession

Stateful realtime WebSocket session with AsyncIterable support.

Create a session through ProsodyClient:

const session = prosody.stream.session(options);

Methods

class LiveSession implements AsyncIterable<ProsodyEvent> {
  start(options?: LiveSessionStartOptions): Promise<void>;

  send(chunk: ArrayBuffer | Uint8Array | Buffer | Int16Array): void;

  sendControl(message: Record<string, unknown>): void;

  waitForFrame(timeoutMs?: number): Promise<void>;

  stop(options?: {
    waitForSessionEndMs?: number;
  }): Promise<SessionEndEvent | null>;

  close(): void;

  snapshot(options?: TranscribeOptions): Transcription;

  [Symbol.asyncIterator](): AsyncIterator<ProsodyEvent>;
}

Properties

readonly conversation: Conversation;
readonly sessionId: string | null;
readonly started: boolean;
readonly readyState: number;
readonly latestDirective: DirectiveEvent | null;
readonly speakerProfiles: SpeakerProfile[];
readonly sessionEnd: SessionEndEvent | null;

Options

interface LiveSessionStartOptions {
  source?: string;
  sourceOffsetMs?: number;
  sampleRate?: number;
  encoding?: 'pcm16' | 'linear16' | 'opus';
  container?: 'ogg' | 'webm';
  analysisMode?: string;
  chunkSeconds?: number;
  sessionId?: string;
  capabilities?: ('transcription' | 'diarization' | 'acoustic_state')[];
}

capabilities declares which stages run on the stream. Leave it out to run all three (transcription, diarization, acoustic_state). Omitting acoustic_state runs words and optional diarization without the acoustic model.

prosody.stream.session() also accepts callback handlers:

onUpdate?: (session: LiveSession) => void;
onError?: (error: Error) => void;
onClose?: (code: number, reason: string) => void;
onEvent?: (event: ProsodyEvent | Record<string, unknown>) => void;
WebSocketImpl?: typeof WebSocket;

Async iteration

LiveSession implements AsyncIterable<ProsodyEvent>, yielding each parsed wire event until session_end or socket close:

const session = prosody.stream.session({ encoding: 'pcm16', sampleRate: 16_000 });
await session.start();

for await (const event of session) {
  if (event.type === 'transcript_update') {
    console.log(event.segments);
  }
}

Lifecycle and backpressure

  • start() resolves on config_ack. Rejects with AuthenticationError on invalid keys or InsufficientCreditsError on depleted balances.
  • waitForFrame(timeoutMs = 10_000) resolves on the next directive or frame_ack to pace recorded file replay.
  • stop() sends the end frame, waits up to waitForSessionEndMs (default 20 s) for session_end, closes the socket, and returns the final event.
  • snapshot() derives Transcription from the current Conversation.

On this page