Skip to main content
Use a bidirectional <Stream> when you want your own WebSocket server to run the speech-to-text, agent, text-to-speech, and barge-in logic for a call.

Resources

Start the WebSocket stream

Return this XML from your call’s Answer URL:
The WebSocket URL is the text content of <Stream>. Use wss:// in production.

Understand the two audio directions

Your inbound and outbound formats can differ. For example, you can decode inbound L16/8 kHz audio and send an outbound L16/24 kHz TTS response.
Do not put contentType="audio/x-l16;rate=24000" on <Stream> to configure 24 kHz TTS playback. That attribute controls inbound Vobiz-to-application audio. Declare 24 kHz on the outbound playAudio event.

Handle WebSocket events

Vobiz sends these events to your application: Your application sends these commands to Vobiz: When the call ends, handle the WebSocket close event. Do not wait for an inbound { "event": "stop" } message.

Decode inbound audio

Save the streamId and initialize your decoder from the start event:
Supported inbound formats are: Base64-decode each media.payload, then pass the raw audio to a decoder or STT service configured for start.mediaFormat. Do not assume the inbound format matches your outbound TTS format.

Send outbound playback

Vobiz accepts these outbound playAudio formats: Send raw mono audio without a WAV, MP3, or other file header:
The payload must genuinely match the declared format. If your TTS provider returns audio at another rate or in a container, convert it before Base64 encoding. Changing only sampleRate does not resample the audio. Send approximately 20–60 ms per playAudio message for responsive barge-in. This is a recommendation, not a protocol requirement.

Track completion and handle barge-in

After the final playback chunk for an utterance, send a checkpoint:
When playback reaches it, Vobiz sends playedStream with the same name. If the caller interrupts, send:
Cleared or interrupted playback may not produce playedStream. Add a timeout so your application does not wait indefinitely.

Processing pipeline

Your STT and TTS providers may require different formats. Convert only at the boundary that needs it, and keep the declared metadata synchronized with the real bytes.
A 24 kHz playAudio payload does not guarantee 24 kHz audio at the handset. The phone-facing carrier, SIP, or PSTN leg may use a lower-rate codec.

Troubleshooting

Confirm the real payload rate matches playAudio.media.sampleRate. Remove file headers and ensure the audio is mono.
Send clearAudio as soon as your voice-activity detector confirms barge-in. Keep playback chunks small so less audio remains queued.
Set bidirectional="true" and keepCallAlive="true". For bidirectional streams, use audioTrack="inbound" or omit audioTrack.
Handle the WebSocket close event. Vobiz does not send an inbound stop JSON event when the call ends.

Next steps