The audio stream element lets you receive raw audio from active calls over a WebSocket connection in near real time.

Attributes

ParameterDescription
bidirectional
(boolean)
Specifies whether the audio being streamed over the WebSocket is bidirectional (read/write) or one-way (read-only).

If true, Plivo accepts:
- event: Takes playAudio as the value
- media: JSON object containing:
- contentType: audio/x-l16, audio/x-mulaw
- sampleRate: 8000, 16000
- payload: Base64-encoded raw audio
audioTrack
(string)
The audio track (inbound/outbound) that Plivo will fork and stream to the WebSocket.

Allowed values: inbound, outbound, both
Default: inbound
Note: When bidirectional is true, audioTrack should not be outbound or both.
streamTimeout
(integer)
Maximum duration (in seconds) for audio streaming. Streaming stops after this duration.
Must be a positive integer.

Default: 86400 (24 hours)
statusCallbackUrl
(string)
URL notified when:
- Audio stream is connected
- Audio stream is stopped intentionally or due to timeout
- Audio stream failed or disconnected
statusCallbackMethod
(string)
HTTP method used to invoke statusCallbackUrl.

Allowed values: GET, POST
Default: POST
contentType
(string)
Preferred audio codec and sampling rate.

Allowed values:
- audio/x-l16;rate=8000
- audio/x-l16;rate=16000
- audio/x-mulaw;rate=8000
Default: audio/x-l16;rate=8000
extraHeaders
(string)
Key-value pairs sent to the WebSocket service with the audio stream.
Example: test1=12,test2=123
Max length: 512 bytes.
Only characters [A-Z], [a-z], [0-9] allowed.
keepCallAlive
(boolean)
If true, this stream element runs alone. Subsequent XML elements execute only after the stream disconnects.

Allowed values: true, false
Default: false

Parameters sent to the statusCallbackUrl

This information is sent to statusCallbackUrl when an event is triggered.
ParameterDescription
bidirectional
(boolean)
Specifies whether the audio being streamed over the WebSocket is bidirectional (read/write) or one-way (read-only).

If true, Plivo accepts:
- event: Takes playAudio as the value
- media: JSON object containing:
-contentType: audio/x-l16, audio/x-mulaw
- sampleRate: 8000, 16000
- payload: Base64-encoded raw audio
audioTrack
(string)
The audio track (inbound/outbound) that Plivo forked and streamed to the WebSocket.

Allowed values: inbound, outbound, both
Default: inbound
Note: When bidirectional is true, audioTrack should not be outbound or both.
streamTimeout
(integer)
Maximum duration (in seconds) that audio was streamed.

Default: 86400 (24 hours)
statusCallbackUrl
(string)
URL that received the notification of one of these events:
- Audio stream connected
- Audio stream stopped or timed out
- Audio stream failed/disconnected
statusCallbackMethod
(string)
HTTP method used to invoke statusCallbackUrl.

Allowed values: GET, POST
Default: POST
contentType
(string)
Audio codec and sampling rate used.

Allowed values:
- audio/x-l16;rate=8000
- audio/x-l16;rate=16000
- audio/x-mulaw;rate=8000
Default: audio/x-l16;rate=8000
extraHeaders
(string)
Key-value pairs sent along with the audio stream.
Example: test1=12,test2=123
Max length: 512 bytes.
Allowed characters: [A-Z], [a-z], [0-9]
keepCallAlive
(boolean)
Indicates whether stream was executed alone before continuing with subsequent XML elements.

Allowed values: true, false
Default: false
from plivo import plivoxml

response = plivoxml.ResponseElement().add(plivoxml.StreamElement('
wss://yourstream.websocket.io/audiostream'))                                         

print(response.to_string())
Response
<Response>
	<Stream bidirectional = "true" keepCallAlive="true" >wss://yourstream.websocket.io/audiostream</Stream>
</Response>