Play Audio
ONLY .wav and .mp3 files as are supported
To ensure playback quality, Bandwidth recommends limiting audio files to less than 1 hour in length or 250 MB in size.
The PlayAudio verb is used to play an audio file in the call. The URL of an audio file should be
included in the body of the <PlayAudio> tag. If a relative URL is given, it is resolved relative to the endpoint that returned the BXML.
Audio is cached according to RFC 7234. Our system may cache your media up to the value of the response's Cache-Control header's max-age directive, or, if none is present, until the time given in an Expires header. In either case, our system may always cache for a shorter amount of time or not cache at all. If no Cache-Control or Expires header is set on the response, media will not be cached.
The audio format is determined by the HTTP Content-Type header in the response. Our system supports:
audio/wavandaudio/x-wavfor.wavfiles- Both
G711 μ-lawandG711 A-laware supported within thepcm_s16lecontainer (signed, 16-bit, little-endian, PCM-encoded.wavfile)
- Both
audio/mpeg,audio/mpeg3, andaudio/mp3for.mp3files- The following standards (and corresponding sample rates) are supported:
MPEG-1 layer 3(48,44.1, and32kHz)MPEG-2 layer 3(24,22.05, and16kHz)MPEG-2.5 layer 3(12,11.025, and8kHz)
- The following standards (and corresponding sample rates) are supported:
Both .wav and .mp3 can be in either mono or stereo format, but they will be mixed down to mono before being played. Using higher-bitrate audio files won't meaningfully improve audio quality and will instead waste bandwidth, so using low bitrate formats such as PCMU (G711 μ-law) is preferred.
If the Content-Type is something other than the ones above or no Content-Type is found, we still try to determine the format by looking at the file extension. If the file extension is missing or it is something other than .mp3 or .wav, we assume the media is .wav and it will be tried as such.
Recordings created with the <Record> or the <StartRecording> verbs can also be played, just use the mediaUrl property sent in the RecordingAvailable callback.
Text Content
| Name | Description |
|---|---|
| audioUri | The URL of the audio file to play. May be a relative URL. |
Attributes
| ATTRIBUTE | Description |
|---|---|
| username | (optional) The username to send in the HTTP request to audioUri. |
| password | (optional) The password to send in the HTTP request to audioUri. |
Webhooks Received
There are no webhooks received after the <PlayAudio> verb is executed.
Examples
Play two Audio Files in Succession
- XML
- Java
- C#
- Ruby
- NodeJS
- Python
- PHP
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<PlayAudio>https://audio.url/audio1.wav</PlayAudio>
<PlayAudio>https://audio.url/audio2.mp3</PlayAudio>
</Response>
PlayAudio playAudio1 = new PlayAudio().builder()
.audioUri("https;//audio.url/audio1.wav")
.build();
PlayAudio playAudio2 = new PlayAudio.builder()
.audioUri("https://audio.url/audio2.mp3")
.build();
Response response = new Response()
.withVerbs(playAudio1, playAudio2);
System.out.println(response.toBXML());
PlayAudio playAudio1 = new PlayAudio
{
Url = "https://audio.url/audio1.wav"
};
PlayAudio playAudio2 = new PlayAudio
{
Url = "https://audio.url/audio2.mp3"
};
Response response = new Response();
response.Add(playAudio1);
response.Add(playAudio2);
Console.WriteLine(response.ToBXML());
play_audio_1 = Bandwidth::Bxml::PlayAudio.new('https://audio.url/audio1.wav')
play_audio_2 = Bandwidth::Bxml::PlayAudio.new('https://audio.url/audio2.mp3')
response = Bandwidth::Bxml::Response.new([play_audio_1, play_audio_2])
p response.to_bxml
const playAudio1 = new Bxml.PlayAudio('https://audio.url/audio1.wav');
const playAudio2 = new Bxml.PlayAudio('https://audio.url/audio2.mp3');
const response = new Bxml.Response([playAudio1, playAudio2]);
console.log(response.toBxml());
play_audio_1 = PlayAudio(
audio_uri="https://audio.url/audio1.wav"
)
play_audio_2 = PlayAudio(
audio_uri="https://audio.url/audio2.mp3"
)
response = Response()
response.add_verb(play_audio_1)
response.add_verb(play_audio_2)
print(response.to_bxml())
$playAudio1 = new BandwidthLib\Voice\Bxml\PlayAudio("https://audio.url/audio1.wav");
$playAudio2 = new BandwidthLib\Voice\Bxml\PlayAudio("https://audio.url/audio2.mp3");
$response = new BandwidthLib\Voice\Bxml\Response();
$response->addVerb($playAudio1);
$response->addVerb($playAudio2);
echo $response->toBxml();