Reference
LiveSession
Stateful realtime WebSocket session
Create a session through ProsodyClient:
const session = prosody.stream.session(options);Methods
class LiveSession {
start(options?: LiveSessionStartOptions): Promise<void>;
send(
chunk: ArrayBuffer | Uint8Array | Buffer | Int16Array,
): void;
waitForFrame(timeoutMs?: number): Promise<void>;
stop(options?: {
waitForSessionEndMs?: number;
}): Promise<SessionEndEvent | null>;
close(): void;
snapshot(options?: TranscribeOptions): Transcription;
}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;
}Session construction additionally accepts:
interface LiveSessionCallbacks {
onUpdate?: (session: LiveSession) => void;
onError?: (error: Error) => void;
onClose?: (code: number, reason: string) => void;
onEvent?: (event: ProsodyEvent | Record<string, unknown>) => void;
WebSocketImpl?: typeof WebSocket;
}Lifecycle
const session = prosody.stream.session({
encoding: 'pcm16',
sampleRate: 16_000,
onUpdate: (current) => render(current.snapshot()),
});
await session.start();
for (const chunk of chunks) {
session.send(chunk);
await session.waitForFrame();
}
const finalEvent = await session.stop();
const result = session.snapshot();start() resolves after config_ack. stop() sends the end frame, waits up
to 20 seconds for session_end, closes the socket, and returns the final event.
Pass { waitForSessionEndMs: 0 } for an immediate stop.
close() closes the socket immediately.
Snapshot
const current: Transcription = session.snapshot();snapshot() derives Transcription from the current Conversation. Committed
speaker-lane and identity updates are reflected on every call.
Backpressure
waitForFrame() resolves on the next directive or frame_ack. The default
timeout is 10 seconds. Use it to pace file replay against the server's analysis
cadence.