VoxML Reference
Stream
Send live call audio to a WebSocket service with VoxML.
Use the VoxML Stream verb to connect an answered call to a WebSocket service. It is intended for real-time transcription, conversational AI, quality monitoring, and other applications that need access to the call audio.
TryVox begins the stream while executing the call's VoxML response. There is currently no separate REST API for creating, listing, retrieving, or stopping stream objects on an already-running call.
Basic example
{
"voxml_version": "1.0",
"instructions": [
{
"verb": "Stream",
"url": "wss://voice.example.com/calls",
"track": "inbound_track",
"parameters": {
"agent_id": "support-assistant",
"language": "en-IN"
}
}
]
}Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
verb | string | yes | — | Must be Stream. |
url | string | yes | — | WebSocket endpoint. Use wss:// in production. |
track | string | no | inbound_track | inbound_track sends the caller side; both_tracks sends a mono mix of both sides. |
parameters | object | no | {} | String-valued metadata delivered as the first WebSocket text frame. |
dtmf | boolean | no | false | Also deliver the caller's key presses as text frames. See Caller keypresses. |
playback_events | boolean | no | false | Tell you when audio you sent has finished playing. See Knowing when your audio finished. |
outbound_track is not currently supported. TryVox returns a stream execution error instead of silently substituting another track.
Choosing a track
Use inbound_track for speech recognition or an AI assistant that should listen to the caller:
{
"verb": "Stream",
"url": "wss://voice.example.com/listen",
"track": "inbound_track"
}Use both_tracks for analytics, compliance, or transcription that needs the complete conversation:
{
"verb": "Stream",
"url": "wss://voice.example.com/analyse",
"track": "both_tracks"
}With both_tracks, the two directions are mixed into one mono channel. They are not delivered as separately labelled tracks.
WebSocket connection
Your server must:
- Accept a WebSocket client connection from TryVox.
- Accept the
audio.drachtio.orgWebSocket subprotocol. - Handle one initial UTF-8 text frame followed by binary audio frames.
- Keep reads non-blocking and process audio continuously.
The connection sequence is:
- TryVox opens the WebSocket.
- TryVox sends the
parametersobject as a JSON text frame. - TryVox sends raw PCM audio in binary frames.
- The connection closes when the call channel or stream ends.
For example, these parameters:
{
"parameters": {
"account_ref": "acct_42",
"conversation_ref": "conv_91"
}
}arrive as the first text frame:
{
"account_ref": "acct_42",
"conversation_ref": "conv_91"
}Do not treat the first text frame as audio.
Audio format
Audio sent from TryVox to your server uses:
| Property | Value |
|---|---|
| Encoding | Signed linear PCM (L16) |
| Sample width | 16-bit |
| Byte order | Little-endian |
| Sample rate | 8,000 Hz |
| Channels | One |
| Container | None; frames contain raw audio bytes |
The audio frames are binary WebSocket messages. They are not JSON objects and are not Base64 encoded.
If your speech or model provider expects 16 kHz audio, resample the PCM stream after receiving it. Do not reinterpret 8 kHz bytes as 16 kHz audio.
Authentication
The url may contain a short-lived, call-scoped token:
{
"verb": "Stream",
"url": "wss://voice.example.com/calls?token=eyJhbGciOi...",
"track": "inbound_track"
}Prefer an expiring token over a permanent API key. Validate it during the WebSocket upgrade and bind it to the expected account or call. Avoid placing reusable account credentials in parameters, because metadata travels inside the established WebSocket rather than authenticating the initial upgrade request.
Custom WebSocket request headers are not currently configurable through the Stream verb.
Caller keypresses
Set dtmf on the verb to receive DTMF digits on the same WebSocket:
{
"verb": "Stream",
"url": "wss://voice.example.com/agent",
"track": "inbound_track",
"dtmf": true
}Each keypress arrives as a UTF-8 JSON text frame:
{ "type": "dtmf", "digit": "5" }digit is a single character: 0–9, *, #, or A–D.
This is off unless you ask for it. Without dtmf, the only text frame TryVox sends is the parameters object at connect, so existing integrations see no change. If you enable it, handle text frames by checking type rather than assuming the first text frame is the only one.
Keypresses are still delivered to a Gather running on the same call — enabling this does not take them away from your IVR.
Knowing when your audio finished
If you hang up as soon as you have sent the last of your audio, the caller loses the end of it: the audio is still queued. If you instead wait a guessed interval, the caller hears silence before the call drops. Guessing from the duration of what you sent is wrong in both directions, because the thing you are trying to predict happens on our side.
Set playback_events and we will tell you instead:
{
"verb": "Stream",
"url": "wss://voice.example.com/agent",
"playback_events": true
}Each clip you sent produces one text frame as it finishes:
{ "type": "playbackFinished", "pending": 0, "status": "done" }| Field | Meaning |
|---|---|
pending | How many clips you sent that have not finished yet. 0 means everything you have sent has played. |
status | FreeSWITCH's own playback status, passed through unchanged, or interrupted for audio cancelled by killAudio. |
pending is the field to act on. Send your goodbye, wait for
pending: 0, then hang up:
ws.on('message', (raw) => {
const msg = JSON.parse(raw)
if (msg.type === 'playbackFinished' && msg.pending === 0 && sentGoodbye) {
setTimeout(() => hangUp(), 200) // see the drain margin below
}
})Leave a drain margin
This event means FreeSWITCH has finished writing your audio into the call. It is not a receipt from the caller's handset. Between the two sit our media relay, the carrier network and the far end's own jitter buffer, and RTP has no way to report playout — so a short gap remains that nobody can measure from either end.
On Indian PSTN we see 20–65 ms of jitter on a normal call. Waiting
150–250 ms after pending: 0 before sending the hangup covers it
comfortably. The point of the event is that what is left to guess at is one
network trip rather than the whole length of your audio.
Use it for the hangup, not for turn-taking
FreeSWITCH takes around 140 ms between finishing one clip and starting the
next. If you wait for pending: 0 before sending every utterance, you add
that gap to every turn and the agent will sound like it is pausing. Keep
sending audio as you generate it, and use these events only where the
precise end actually matters — before a hangup, or before handing the turn
over.
Barge-in
When you send killAudio, anything still queued is cancelled and you get one
final frame:
{ "type": "playbackFinished", "pending": 0, "status": "interrupted" }The cancelled clips do not each report separately. This means a state machine
waiting for pending: 0 always gets it, whether the audio finished or was
interrupted — check status if you need to tell the two apart.
This is off unless you ask for it, for the same reason dtmf is: without it
the only text frame TryVox sends is the parameters object at connect. Handle
text frames by checking type.
A keypad opt-out is required for outbound campaigns under TRAI rules. Use this if your agent runs on the stream socket rather than through Gather.
Stream termination
The WebSocket close event is the stream-level termination signal. Release model sessions, buffers, and temporary resources when it arrives.
Closing the WebSocket does not end the call. The stream and the call are separate: closing the socket stops the audio feed and leaves the call up. If your agent is finished with a call, hang the call up explicitly — see below.
The stream is a feed attached to a call, not the call itself, and the
relationship is not symmetric. Ending a call always closes its stream, but
closing a stream does not end its call. A stream can close because of a call
hangup, a network failure, your own process restarting, or media-server
shutdown — so the close event alone tells you neither why it closed nor how
the call ended. For the authoritative call result, configure the call's
hangup_url.
Ending a call from your agent
The stream protocol has no hangup message. To end a call, use the call API:
https://api.tryvox.io/v1/voice/accounts/{auth_id}/calls/{call_uuid}See Hang up a call for the full request and responses.
Do this whenever your agent decides the conversation is over. Do it as well when your agent fails or is shutting down, if you want the caller released rather than left on a silent line.
If you never hang up
If your stream closes and the call is still up 5 minutes later, TryVox ends it. A call that was transferred elsewhere in the meantime is left alone, and a stream that reconnects within those 5 minutes cancels the countdown. Separately, no call may run longer than 4 hours.
Both are backstops against a call that can never recover, not a substitute for hanging up: until a backstop fires the call is live and billable, and a caller still on the line hears nothing. A dropped stream your side does not act on therefore costs up to five minutes of billed silence per call.
TryVox does not currently emit separate Stream status callbacks or expose a Stream ID.
Sending audio toward the call
The same WebSocket can send audio back to the caller. Send a UTF-8 JSON text frame with type: "playAudio":
{
"type": "playAudio",
"data": {
"audioContentType": "raw",
"sampleRate": 8000,
"audioContent": "BASE64_ENCODED_PCM_AUDIO"
}
}audioContent must be Base64-encoded mono signed linear PCM. For raw audio, sampleRate must be 8000 or 16000. You may instead send a complete WAV file by setting audioContentType to wave and Base64-encoding the file.
Send messages in playback order, as soon as each is ready — do not pace them to real time.
Consecutive messages are joined into a single playback, so audio that arrives while an earlier message is still playing continues from it without a seam. You do not need to buffer a whole utterance before sending it: a reply still being generated can go out in as many pieces as it arrives in. Verified on a live call, twelve consecutive 250 ms chunks of a continuous tone play as one unbroken three-second tone.
Two practical limits remain. Audio that arrives after a batch has started playing waits for that batch to finish, so there is still a boundary between batches — it is not a single continuous buffer you can write into at an arbitrary rate. And messages are dispatched through a bounded internal queue, so a sustained flood arriving faster than the call can play it will still shed audio rather than queue indefinitely.
Interrupting the agent (barge-in)
When the caller starts speaking over the agent, send a killAudio text frame:
{ "type": "killAudio" }This stops audio that is currently playing and discards anything you have already sent that has not started yet. Without it, queued audio would begin playing the moment the current chunk was cut short and the caller would still be talked over.
Detecting the interruption is your side's job — you have the caller's audio in
real time, so run your own voice-activity or turn detection and send killAudio
as soon as you decide the caller has the floor.
Because sent audio can be cancelled this way, it is safe to send a reply as soon as it is ready rather than waiting to be certain the caller has finished.
checkpoint and stop are not defined. Use the WebSocket close event for
stream cleanup and the call API or VoxML for call control.
A mark message is accepted by the media server but cannot currently tell you
what the caller heard: it is only echoed back when killAudio discards the
queue, never when audio finishes playing. Do not use it as a playback
checkpoint. If you need to know whether a reply reached the caller, track it
from your own side using the timing of the audio you sent.
AI assistant example
{
"voxml_version": "1.0",
"instructions": [
{
"verb": "Say",
"text": "Please wait while I connect the assistant."
},
{
"verb": "Stream",
"url": "wss://assistant.example.com/media?session=short-lived-token",
"track": "inbound_track",
"parameters": {
"assistant": "customer-care",
"locale": "en-IN"
}
}
]
}Operational guidance
- Use
wss://with a publicly trusted certificate in production. - Authorize the WebSocket during the upgrade, before accepting audio.
- Expect the first frame to be text and all subsequent audio frames to be binary.
- Apply backpressure and keep per-frame processing short.
- Resample explicitly when downstream services require another sample rate.
- Treat WebSocket disconnects as stream-level cleanup only — they do not end the call. Hang the call up with
DELETE /v1/voice/accounts/{auth_id}/calls/{call_uuid}when your agent is done or is shutting down, and usehangup_urlfor the final call status. - Do not log access tokens or raw call audio unless your retention and consent policies allow it.
Current limitations
- Streams can only be started through VoxML.
- The input format is fixed to 8 kHz L16.
- Only
inbound_trackand mono-mixedboth_tracksare supported. - Stream IDs, REST lifecycle operations, reconnect controls, status callbacks, and custom upgrade headers are not exposed.
- Bidirectional playback supports
playAudio; checkpoint, clear, and stop control events are not exposed.