Skip to main content

Start Stream

The StartStream verb allows a segment of a call to be sent off to another destination for additional processing.

When used on a call, audio from one or both sides (tracks) of the call will be sent to the specified destination. The stream will continue until the call ends or the <StopStream> verb is used. A total of 4 concurrent track streams are allowed on a call. A <StartStream> request that uses both tracks will count as 2 concurrent streams. A call has only two tracks, which are named after the direction of the media from the perspective of the Programmable Voice platform:

  • inbound: media received by Programmable Voice from the call executing the BXML;
  • outbound: media sent by Programmable Voice to the call executing the BXML.

Note that this has no correlation to the direction of the call itself. For example, if either an inbound or outbound call is being streamed and executes a <SpeakSentence>, the inbound track will be the callee's audio and the outbound track will be the text-to-speech audio.

Text Content

There is no text content available to be set for the <StartStream> verb.

Attributes

AttributeDescription
name(optional) A name to refer to this stream by. Used when sending <StopStream>. If not provided, it will default to the generated stream id as sent in the Media Stream Started webhook.
tracks(optional) The part of the call to send a stream from. inbound, outbound or both. Default is inbound.
destination(required) A websocket URI to send the stream to. The audio from the specified tracks will be sent via websocket to this URL as base64-encoded PCMU/G711 audio. See below for more details on the websocket packet format.
streamEventUrl(optional) URL to send the associated Webhook events to during this stream's lifetime. Does not accept BXML. May be a relative URL.
streamEventMethod(optional) The HTTP method to use for the request to streamEventUrl. GET or POST. Default value is POST.
username(optional) The username to send in the HTTP request to streamEventUrl. If specified, the URLs must be TLS-encrypted (i.e., https).
password(optional) The password to send in the HTTP request to streamEventUrl. If specified, the URLs must be TLS-encrypted (i.e., https).

If the streamEventUrl attribute is specified, then the Media Stream Started, Media Stream Rejected and Media Stream Stopped events will be sent to the URL when the stream starts, if there is an error starting the stream and when the stream ends respectively. BXML returned in response to this callback will be ignored.

note

While multiple streams for the same call are allowed, each stream MUST have a unique name. Attempting to start a stream on the same call with the name of an already existing stream will result in a Media Stream Rejected event.

Webhooks Received

WebhooksCan reply with more BXML
Media Stream StartedNo
Media Stream RejectedNo
Media Stream StoppedNo

Nested Tags

You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag. These elements define optional user specified parameters that will be sent to the destination URL when the stream is first started.

StreamParam Attributes

AttributeDescription
name(required) The name of this parameter, up to 256 characters.
value(required) The value of this parameter, up to 2048 characters.

Websocket Packet Format

At the destination end, the websocket will receive messages containing JSON for the duration of the stream. There will be an initial start message when the connection is first established. This will be followed by zero or more media messages containing the encoded audio for the tracks being streamed. Finally, when a stream is stopped, a stop message will be sent.

Start and Stop Message Parameters

ParameterDescription
eventTypeWhat type of message this is, one of start, or stop
metadataDetails about the stream this message is for. See further details below.
streamParams(optional) (start message only) If any <StreamParam/> elements were specified in the <StartStream> request, they will be copied here as a map of name : value pairs

Metadata Parameters

ParameterDescription
accountIdThe user account associated with the call
callIdThe call id associated with the stream
streamIdThe unique id of the stream
streamNameThe user supplied name of the stream
tracksA list of one or more tracks being sent in this stream
tracks.nameThe name of the track being sent, will be used to identify which media messages belong to which track
tracks.mediaFormatThe format the media will take for this track
tracks.mediaFormat.encodingThe encoding of the media for this track; currently only audio/PCMU is supported
tracks.mediaFormat.sampleRateThe sample rate of the media for this track, currently only 8000 is supported

Media Message Parameters

ParameterDescription
eventTypeWill always be media
trackThe name of the track this media packet is for, will be one of the names specified in the start message
payloadA base64 encoded string of actual media. The encoding of the media itself is as specified in the start message

Examples

Stream Both Legs of A Call

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<SpeakSentence voice="bridget">This call is being streamed to a live studio audience.</SpeakSentence>
<StartStream name="live_audience" tracks="both" destination="wss://live-studio-audience.myapp.example.com" streamEventUrl="https://myapp.example.com/noBXML">
<StreamParam name="internal_id" value="call_ABC" />
</StartStream>
<SpeakSentence voice="bridget">This will now be streamed to the destination as well as played to the call participants.</SpeakSentence>
</Response>

A start Websocket Message

{
"eventType": "start",
"metadata": {
"accountId": "5555555",
"callId": "c-2a913f94-7fa91773-a426-4118-8b8b-b691ab0a0ae1",
"streamId": "s-2a913f94-93e372e2-60da-4c89-beb0-0d3a219b287c",
"streamName": "live_audience",
"tracks": [
{
"name": "inbound",
"mediaFormat": {
"encoding": "PCMU",
"sampleRate": 8000
}
},
{
"name": "outbound",
"mediaFormat": {
"encoding": "PCMU",
"sampleRate": 8000
}
}
]
},
"streamParams": {
"foo": "bar",
"foos": "bars"
}
}

A media Websocket Message

{
"eventType": "media",
"track": "inbound",
"payload": "3Ob2dV1NRUpSXfTy69bHvbzD09PL0trpaWZMTV5PT05DRUpNYeLyb+jc1tPW3tfN1/r4cFZd5PxXXGjo2M/M0NTU0Nvi31ZFTFhLQERKT19safHd18zIycjHyc3Z4+7s609GSktMS1hmVFBm3eZk2tB4ffJ17/5r5dLb5uLd1c3UdmZnc/jt3eH9a3H06dvV3WNPYXxjS0BJT05VXm53+A=="
}

A stop Websocket Message

{
"eventType": "stop",
"metadata": {
"accountId": "5555555",
"callId": "c-2a913f94-7fa91773-a426-4118-8b8b-b691ab0a0ae1",
"streamId": "s-2a913f94-93e372e2-60da-4c89-beb0-0d3a219b287c",
"streamName": "live_audience",
"tracks": [
{
"name": "inbound",
"mediaFormat": {
"encoding": "PCMU",
"sampleRate": 8000
}
},
{
"name": "outbound",
"mediaFormat": {
"encoding": "PCMU",
"sampleRate": 8000
}
}
]
}
}