What HappensWhen Vobiz encounters a
Stream element in your XML response:- Vobiz initiates a WebSocket connection to your specified URL
- Once connected, raw audio packets are streamed in real-time
- Your application can process, analyze, or forward the audio
- For bidirectional streams, your app can also send audio back to the call
XML Setup
To initiate an audio stream, include theStream element in your XML response with the WebSocket URL:
Basic Stream XML
Key Configuration Parameters
- WebSocket URL: The text content of the element (e.g.,
wss://stream.vobiz.ai/stream). Must be publicly reachable; usewss://(TLS) in production -ws://is for local testing only. - bidirectional: Set to
trueto enable sending audio back to the call. RequiresaudioTrack="inbound"(or omit it). - audioTrack:
inbound(caller),outbound(callee), orboth. Defaultinbound. Do not combineboth/outboundwithbidirectional="true". - contentType: Inbound codec and rate that Vobiz sends to your application. Use
audio/x-l16;rate=8000(default),audio/x-l16;rate=16000, oraudio/x-mulaw;rate=8000. Vobiz reports the selected format instart.mediaFormat. - streamTimeout: Maximum streaming duration in seconds (default: 86400 / 24 hours). When reached, Vobiz stops the stream and (for server-side termination) fires
Event=StopStream. - keepCallAlive: Set to
trueto prevent the call from hanging up when the stream ends or encounters an error. Requiresbidirectional="true". - maxRetries: Reconnect attempts if the WebSocket fails to open or drops mid-stream. Default
0(disabled), max10. - statusCallbackUrl / extraHeaders: See the full attribute reference on the
<Stream>element page.
<Stream contentType> configures inbound Vobiz-to-application audio. It does not configure the audio your application sends back. For outbound playback, set playAudio.media.contentType and playAudio.media.sampleRate on each playAudio event.WebSocket Connection
Your WebSocket server must be ready to accept connections from Vobiz. Here’s what the initial connection looks like:Connection Start Message
Vobiz sends this when the stream starts
start object. start.mediaFormat reports the inbound format Vobiz will use for subsequent media events.
Audio Data Messages
Continuous 20 ms audio frames sent during the stream
media frames per second (one every 20 ms) while the call is active. media.payload contains base64-encoded raw audio in the inbound format declared by start.mediaFormat. Individual media events do not repeat contentType or sampleRate, so initialize your decoder from the start event.
End of stream
When the call ends, the sequence Vobiz sends over the WebSocket is:- The final
mediaframe (no special marker - its shape is identical to every othermediaframe). - The WebSocket
closeevent - this is the end-of-stream signal. - Out-of-band: the
hangup_urlHTTP webhook fires with the fullEvent=Hanguppayload (HangupCause,Duration,EndTime, etc).
Handle end of stream from your close handler
streamTimeout being reached, or your own server sending a stop command.
Connection Flow
- Vobiz receives your XML response containing the Stream element
- WebSocket connection established to your specified URL
- “start” event sent with call metadata and stream configuration
- Continuous “media” events stream audio packets in real-time
- Bidirectional streams (optional): Your app can send playAudio events back to Vobiz
- WebSocket close - the final
mediaframe is followed by a socket close (no inboundstopevent) hangup_urlwebhook fires with the authoritativeEvent=Hanguppayload
Reconnects and idempotency
If the WebSocket fails to open or drops mid-stream and you setmaxRetries (1-10) on the <Stream> element, Vobiz retries the connection. Each retry is a fresh connection: it opens a new socket and replays a new start event with a new streamId (the callId stays the same).
Design your handler to be idempotent across reconnects:
- Key per-call state on
start.callId, notstart.streamId, so a reconnect resumes the same logical session. - Expect to receive a second
startafter a drop. Re-send your greeting only if the conversation hadn’t progressed, or resume from saved state. - A
closeyou see may be a transient drop that Vobiz will retry, not the end of the call. The authoritative end-of-call signal is thehangup_urlEvent=Hangupwebhook (see below).
maxRetries="0" (the default), a dropped socket is terminal.
Implementation Examples
Node.js WebSocket Server
Simple WebSocket server to receive audio
Python WebSocket Handler
Python asyncio WebSocket server
Vobiz XML Response with Stream
Complete example with status callbacks