Voice WebSockets
Use stream tokens to connect to live voice calls.
Connect a standard WebSocket client to the stream_url returned by POST /calls/{id}/stream-token. The currently published SDKs do not expose voice helpers; see the direct HTTP examples.
Start and connect
Create a call and stream token using the manual REST flow, then set PINNACLE_STREAM_URL to the returned URL in your server environment. Keep this short-lived bearer credential private.
Requires Node.js 24 or later.
const streamUrl = process.env.PINNACLE_STREAM_URL;
if (!streamUrl) throw new Error("Set PINNACLE_STREAM_URL from the stream-token response");
const socket = new WebSocket(streamUrl);
socket.addEventListener("open", () => {
socket.send(JSON.stringify({
event: "command",
command_id: crypto.randomUUID(),
action: "audio.play",
params: { text: "Thanks for calling." },
}));
});
socket.addEventListener("message", (message) => {
const frame = JSON.parse(String(message.data));
console.log(frame.event);
});
socket.addEventListener("error", () => console.error("Voice socket failed"));Reconnects and token expiry
These examples do not automatically reconnect. When reconnecting, request a fresh token for the same call rather than reusing an expired stream_url. Limit retries, add backoff, and stop reconnecting once the call has ended. Track command IDs and acknowledgements before retrying a command that may already have run.
Frames and commands
The voice socket carries command frames, optional raw audio frames, and server frames. Send JSON command frames and listen for event / ack.
| Direction | Frame | Purpose |
|---|---|---|
| App to Pinnacle | command | Control the call: answer, transfer, play audio, gather input, update metadata, and more. |
| App to Pinnacle | media | Send generated outbound audio into the call. Most apps use audio.play instead. |
| Pinnacle to app | ack | Confirms whether a command was accepted. It echoes your command_id. |
| Pinnacle to app | event / media | Delivers call lifecycle events, input results, and inbound audio. |
Command frames
All commands use the same JSON envelope:
{
"event": "command",
"command_id": "cmd_play",
"action": "audio.play",
"params": {
"text": "Thanks for calling.",
"voice": "female",
"language": "en-US"
}
}The matching acknowledgement echoes command_id and includes a monotonic sequence_number.
| Field | Meaning |
|---|---|
event | Always ack. |
command_id | The ID you sent on the command frame. |
action | The command action that was acknowledged. |
status | ok when the command was accepted. |
sequence_number | Server-side ordering value. |
Command catalog
See the Voice Command Reference for all 19 commands, required and optional fields, and example payloads.
Audio frames
Most apps should not send audio frames directly.
Use audio.play when you want to play TTS or an audio file from a public URL. Use raw audio frames only when you need to stream audio from your own app in realtime.
For files like MP3, WAV, M4A, MP4, or MOV:
- Prefer hosting the file and playing it with
audio.play. - If you must stream the bytes yourself, convert the file to raw 8 kHz mono mu-law audio.
- Split the converted bytes into small chunks.
- Base64 each chunk and send it as
media.payload.
Convert almost any local audio or video file with FFmpeg:
ffmpeg -i input.mp3 -vn -ac 1 -ar 8000 -f mulaw output.ulawThe same command works for formats FFmpeg can read, including .wav, .m4a, .mp4, and .mov. The output.ulaw file is raw audio bytes. It is not a WAV file and does not have a header.
Send each chunk with this frame shape:
{
"event": "media",
"media": {
"track": "outbound",
"payload": "base64-mulaw-audio",
"chunk": 1,
"timestamp": "2026-06-24T00:00:00.000Z"
}
}The important field is media.payload: it is one base64-encoded chunk from output.ulaw. A 20 ms chunk is a recommended default, not a protocol requirement. At 8 kHz, 20 ms is 160 bytes before base64 encoding.
| Field | What to send |
|---|---|
media.track | Use outbound for audio you send into the call. |
media.payload | Base64 for one raw 8 kHz mono mu-law chunk. |
media.chunk | Optional counter. Start at 1 and increment per chunk. |
media.timestamp | Optional timestamp for the chunk. |
Chunk converted audio
These examples assume audio contains the bytes from output.ulaw.
function mediaFramesFromMulawBytes(audio: Uint8Array) {
const chunkSize = 160;
const frames = [];
for (let offset = 0; offset < audio.length; offset += chunkSize) {
const chunk = audio.subarray(offset, offset + chunkSize);
frames.push({
event: "media",
media: {
track: "outbound",
payload: Buffer.from(chunk).toString("base64"),
chunk: frames.length + 1,
},
});
}
return frames;
}
const frames = mediaFramesFromMulawBytes(Buffer.from([255, 127, 0, 127]));In your app, a good default is to send one frame about every 20 ms by JSON-encoding the complete media frame and sending it over the open WebSocket. This is recommended, not required. At 8 kHz, 20 ms is 160 audio bytes, which keeps latency low without creating excessive WebSocket traffic.
If you are generating audio live, ask your audio provider for 8 kHz mono mu-law / PCMU output when possible. If it gives you PCM, MP3, or another format, run the same conversion step before chunking.
Receiving audio
Inbound audio from Pinnacle uses the same media.payload format. Server frames include stream_sid and sequence_number so you can keep chunks in order:
{
"event": "media",
"stream_sid": "stream_123",
"sequence_number": 42,
"media": {
"track": "inbound",
"payload": "base64-mulaw-audio",
"chunk": 7,
"timestamp": "2026-06-24T00:00:01.400Z"
}
}SDK availability
Use your language's WebSocket client with the JSON frames documented above and the voice command reference. These examples do not require SDK-specific voice types or helpers.