Measurement streams
Feed speaker-attributed voice measurements into your own application, and read a voice agent call in a LiveKit room
ProsodyAI streams committed speaker lanes, transcript deltas, physical voice measurements, and speaker-relative change. Your application decides how those facts affect its own logic, such as an LLM prompt or a call-center dashboard.
import { VoiceFrame } from '@prosodyai/sdk';
const stream = prosody.stream.connect({
onDirective(event) {
const frame = VoiceFrame.fromDirective(event);
appContext.update({
speaker: frame.speakerId,
pitch: frame.state?.intonation.pitch,
loudness: frame.state?.stress.loudness,
change: frame.change,
vad: frame.vad,
});
},
});The WebSocket audio clock advances continuously. Speaker attribution and speaker-relative state come from the model's recurrent lanes. Product events carry measurements and committed identity facts.
Voice agent calls
A voice agent call is a LiveKit room. The Talk tab in the demo runs one.
- One request opens the room. Your server sends
POST /v1/realtime/sessionswith its API key. The response carries the room:server_url,room_name,participant_token,participant_identity,session_id,expires_at,event_topic, andcontrol_topic. The key stays on your server. - The caller joins with the token. The browser connects to
server_urlwithparticipant_tokenand publishes the caller's microphone. The token dispatches the agent into the room, and the agent's voice arrives as an ordinary audio track. - The speech model is chosen on the server. The request's optional
voicefield names the speech model that speaks on the call, fixed when the call starts. Leave it out and the deployment's default serves. The browser code is the same for every speech model. - The call runs transcription and diarization. ProsodyAI commits the
callers' words, who spoke them, and each turn change. The agent's own
words carry the
speaker_idagent. - The call reads like any LiveKit agent. Each line is a LiveKit
transcription segment on the
lk.transcriptiontext stream, sent as the participant who spoke it and marked final when it is whole. A caller's segment may carry the optional attributesprosody.speaker_idandprosody.speaker_name. The agent reportsinitializing,listening, orspeakingon itslk.agent.stateparticipant attribute. LiveKit's Agents UI components (AgentSessionProvider,AgentChatTranscript,AgentControlBar, the audio visualizers) render the call with no ProsodyAI-specific code; the Talk tab in the demo is built from them. - Committed events reach the room. The agent also publishes each
committed event as one JSON message on the data topic named in
event_topic. Every message has atype:prosodyai.transcriptcarries words with theirspeaker_id,prosodyai.speaker_changemarks a new voice on the floor, andturn_boundarymarks a turn change. See Turn changes and barge-ins for theturn_boundaryfields.
The request body takes these optional fields:
| Field | Description |
|---|---|
participant_name | Display name for the caller in the room |
session_id | Joins the room of an existing session that belongs to your organization |
agent_name | The agent the room dispatches. Leave it out and the deployment's configured agent serves |
voice | The speech model that speaks on the call. Ignored when joining an existing session |
Open the room from your server:
const response = await fetch('https://api.prosodyai.app/v1/realtime/sessions', {
method: 'POST',
headers: {
'X-API-Key': process.env.PROSODY_API_KEY!,
'Content-Type': 'application/json',
},
body: JSON.stringify({ participant_name: 'Caller' }),
});
const session = await response.json();Join from the browser and read the committed events. The SDK's
RoomTranscript builds the transcript from the data topic:
import { Room, RoomEvent } from 'livekit-client';
import { RoomTranscript } from '@prosodyai/sdk';
const room = new Room();
const transcript = new RoomTranscript();
room.on(RoomEvent.DataReceived, (payload, participant, _kind, topic) => {
if (topic !== session.event_topic || !participant?.isAgent) return;
transcript.observe(JSON.parse(new TextDecoder().decode(payload)));
render(transcript.all());
});
await room.connect(session.server_url, session.participant_token);
await room.localParticipant.setMicrophoneEnabled(true);A call carries words, speakers, and turn changes. Voice measurement, identity, and memory come from the analysis API: Recorded analysis and Live analysis.
Application policy
Build policy in your application from the measurements your use case needs.
For example, compare change.stress.loudness or change.intonation.pitch
with the same speaker's prior state, then record the decision in your own
trace.
Event inputs
A directive on the live analysis socket carries these fields:
| Field | Type | Description |
|---|---|---|
speaker_id | string | Committed conversation-local lane |
acoustic_state | object | Current physical measurements and masks |
acoustic_change | object | Change against that speaker's recurrent reference |
timestamp_ms | number | Position on the session audio clock |