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

Attributes

bidirectionalboolean

Specifies whether the audio being streamed over the WebSocket is bidirectional (the service can both read and write audio over the WebSocket) or one-way (read-only).

If the bidirectional attribute is set to true, then Plivo accepts the below parameters to accept the audio stream from your application over the WebSockets.

 

Allowed values:

event: Takes playAudio as the value

media: Takes a JSON input of the key values below

contentType: audio/x-l16, audio/x-mulaw

sampleRate: 8000 and 16000

payload: Base64-encoded raw audio

audioTrackstring

The audio track (inbound or outbound) of the underlying call that Plivo will fork and stream to the WebSocket service.
Allowed values:
inbound (only audio received by Plivo from call participants is streamed over WebSocket), outbound (only audio transmitted by Plivo to call participants is streamed over WebSocket), both(both inbound and outbound audio is streamed over the WebSocket). Default is inbound.

Note: When the bidirectional value is set to true, the audioTrack value should not be set to outbound or both.
streamTimeoutinteger

The maximum duration, in seconds, for which audio will be streamed once streaming starts. At the end of the specified duration, streaming will stop. This will have no impact on the rest of the call flow.
Needs to be a positive integer if provided. Defaults to 86,400 (24 hours).

statusCallbackUrlstring

URL notified by Plivo when one of the following events occurs:

  • Audio stream is connected and audio begins streaming (first packet is sent)
  • Audio stream is stopped intentionally or when audio stream timeout is reached
  • Audio stream failed to connect or got disconnected for any reason during an ongoing call
statusCallbackMethodstring

The HTTP verb used to invoke the status_callback_url.
Allowed values:
GET, POST Defaults to POST.

contentTypestring

Preferred audio codec and sampling rate.
Allowed values: audio/x-l16;rate=8000, audio/x-l16;rate=16000, audio/x-mulaw;rate=8000 Defaults to audio/x-l16;rate=8000.

extraHeadersstring

Key-value pairs passed to the WebSocket service along with the audio stream. These extra headers will be passed with every HTTP request made by the call.
Takes string of key-value pairs as input. Example: “test1=12,test2=123”. Total length of the string being passed should be no more than 512 bytes. Only [A-Z], [a-z], and [0-9] characters are allowed in both key and value.

keepCallAliveBoolean

This parameter signifies whether the stream element should be executed alone, without proceeding to execute the subsequent elements in the XML instruction. It applies only when the bi-directional audio stream is set to true. Any elements following the stream in the XML instruction will execute only after the stream is disconnected.
Allowed values: true, false
Default: false

Parameters sent to the statusCallbackUrl

This information is sent to statusCallbackUrl when an event is triggered.

bidirectionalboolean

Specifies whether the audio being streamed over the WebSocket is bidirectional (the service can both read and write audio over the WebSocket) or one-way (read-only).

If the bidirectional attribute is set to true, then Plivo accepts the below parameters to accept the audio stream from your application over the WebSockets.

 

Allowed values:

event: Takes playAudio as the value

media: Takes a JSON input of the key values below

contentType: audio/x-l16, audio/x-mulaw

sampleRate: 8000 and 16000

payload: Base64-encoded raw audio

audioTrackstring

The audio track (inbound or outbound) of the underlying call that Plivo will fork and stream to the WebSocket service.
Allowed values:
inbound (only audio received by Plivo from call participants is streamed over WebSocket), outbound (only audio transmitted by Plivo to call participants is streamed over WebSocket), both(both inbound and outbound audio is streamed over the WebSocket). Default is inbound.

Note: When the bidirectional value is set to true, the audioTrack value should not be set to outbound or both.
streamTimeoutinteger

The maximum duration, in seconds, for which audio will be streamed once streaming starts. At the end of the specified duration, streaming will stop. This will have no impact on the rest of the call flow.
Needs to be a positive integer if provided. Defaults to 86,400 (24 hours).

statusCallbackUrlstring

URL notified by Plivo when one of the following events occurs:

  • Audio stream is connected and audio begins streaming (first packet is sent)
  • Audio stream is stopped intentionally or when audio stream timeout is reached
  • Audio stream failed to connect or got disconnected for any reason during an ongoing call
statusCallbackMethodstring

The HTTP verb used to invoke the status_callback_url.
Allowed values:
GET, POST Defaults to POST.

contentTypestring

Preferred audio codec and sampling rate.
Allowed values: audio/x-l16;rate=8000, audio/x-l16;rate=16000, audio/x-mulaw;rate=8000 Defaults to audio/x-l16;rate=8000.

extraHeadersstring

Key-value pairs passed to the WebSocket service along with the audio stream. These extra headers will be passed with every HTTP request made by the call.
Takes string of key-value pairs as input. Example: “test1=12,test2=123”. Total length of the string being passed should be no more than 512 bytes. Only [A-Z], [a-z], and [0-9] characters are allowed in both key and value.

keepCallAliveBoolean

This parameter signifies whether the stream element should be executed alone, without proceeding to execute the subsequent elements in the XML instruction. It applies only when the bi-directional audio stream is set to true. Any elements following the stream in the XML instruction will execute only after the stream is disconnected.
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>