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
Event
(string)
Allowed values:
- StartStream: sent when audio begins streaming post connection establishment.
- StopStream: sent when the audio stream is stopped intentionally or stream timeout has been reached.
- DroppedStream: sent when the audio stream failed to connect or got disconnected during an ongoing call.
- ClearedAudio: Transmitted when buffered audio files are cleared following the clearAudio command.
- PlayedStream: Acknowledgment of the checkpoint event when all preceding media events before the checkpoint have been successfully played back to the end user.
Note: No callback is sent when a call (rather than a stream) gets disconnected.
Error
(string)
May be Could not establish connection with the remote service or Connection disconnected with the remote service.
Populated only if value of StreamAction is dropped; empty otherwise.
CallUUID
(string)
Unique identifier for this call.
From
(string)
Caller number or SIP endpoint of the CallUUID sent for audio streaming.
To
(string)
Destination number or SIP endpoint of the CallUUID sent for audio streaming.
ServiceURL
(string)
WebSocket URL to which the audio stream is connected.
ExtraHeaders
(string)
Key-value pairs passed as part of the audio Stream XML element.
StreamID
(string)
Unique identifier for each audio stream.
Timestamp
(timestamp)
The timestamp of when the event was generated.
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>