<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
- GitHub repository: Vobiz-Python-Voice-API-Example
- Stream reference:
<Stream>XML element - Event reference: Stream events
Start the WebSocket stream
Return this XML from your call’s Answer URL:<Stream>. Use wss:// in production.
Understand the two audio directions
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 thestreamId and initialize your decoder from the start event:
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 outboundplayAudio formats:
Send raw mono audio without a WAV, MP3, or other file header:
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:playedStream with the same name. If the caller interrupts, send:
playedStream. Add a timeout so your application does not wait indefinitely.
Processing pipeline
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
Playback is slow, fast, or robotic
Playback is slow, fast, or robotic
Confirm the real payload rate matches
playAudio.media.sampleRate. Remove file headers and ensure the audio is mono.The agent does not stop when the caller speaks
The agent does not stop when the caller speaks
Send
clearAudio as soon as your voice-activity detector confirms barge-in. Keep playback chunks small so less audio remains queued.The call ends immediately
The call ends immediately
Set
bidirectional="true" and keepCallAlive="true". For bidirectional streams, use audioTrack="inbound" or omit audioTrack.Cleanup never runs
Cleanup never runs
Handle the WebSocket
close event. Vobiz does not send an inbound stop JSON event when the call ends.