Skip to main content
The <Stream> element streams raw audio from active calls over a WebSocket connection in near real-time. Use it for real-time speech processing, transcription, or AI voice applications.

Basic Usage


Attributes


Audio Formats


Bidirectional Streaming

Enable two-way audio for voice AI applications:
When bidirectional="true", your WebSocket server can send audio back:
When bidirectional is true, audioTrack cannot be outbound or both.

Stream Both Directions

Capture audio from both parties:

Status Callbacks

Monitor stream connection status:

Callback Events

Notifications sent when:
  • Audio stream is connected
  • Audio stream is stopped (intentionally or timeout)
  • Audio stream failed or disconnected

Callback Parameters


Custom Headers

Pass metadata to your WebSocket server:
Constraints:
  • Max length: 512 bytes
  • Allowed characters: [A-Z], [a-z], [0-9]

Keep Call Alive

Wait for stream to end before continuing:
When keepCallAlive="true":
  • Stream element runs exclusively
  • Subsequent XML executes only after stream disconnects

Noise Cancellation

Filter out background noise in real-time to improve voice clarity and transcription accuracy for voice agent applications in noisy environments.
Choosing a cancellation level: Start with the default value of 85. Increase toward 100 for heavy background noise. Decrease toward 60 if you notice audio artifacts or voice distortion.

Use Cases


WebSocket Events

Your WebSocket server receives: For detailed event protocol, see Stream Event Protocol.