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.

  1. One request opens the room. Your server sends POST /v1/realtime/sessions with its API key. The response carries the room: server_url, room_name, participant_token, participant_identity, session_id, expires_at, event_topic, and control_topic. The key stays on your server.
  2. The caller joins with the token. The browser connects to server_url with participant_token and publishes the caller's microphone. The token dispatches the agent into the room, and the agent's voice arrives as an ordinary audio track.
  3. The speech model is chosen on the server. The request's optional voice field 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.
  4. 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_id agent.
  5. The call reads like any LiveKit agent. Each line is a LiveKit transcription segment on the lk.transcription text stream, sent as the participant who spoke it and marked final when it is whole. A caller's segment may carry the optional attributes prosody.speaker_id and prosody.speaker_name. The agent reports initializing, listening, or speaking on its lk.agent.state participant 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.
  6. 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 a type: prosodyai.transcript carries words with their speaker_id, prosodyai.speaker_change marks a new voice on the floor, and turn_boundary marks a turn change. See Turn changes and barge-ins for the turn_boundary fields.

The request body takes these optional fields:

FieldDescription
participant_nameDisplay name for the caller in the room
session_idJoins the room of an existing session that belongs to your organization
agent_nameThe agent the room dispatches. Leave it out and the deployment's configured agent serves
voiceThe 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:

FieldTypeDescription
speaker_idstringCommitted conversation-local lane
acoustic_stateobjectCurrent physical measurements and masks
acoustic_changeobjectChange against that speaker's recurrent reference
timestamp_msnumberPosition on the session audio clock

On this page