Skip to main content

Play Audio

tip

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/wav and audio/x-wav for .wav files
    • Both G711 μ-law and G711 A-law are supported within the pcm_s16le container (signed, 16-bit, little-endian, PCM-encoded .wav file)
  • audio/mpeg, audio/mpeg3, and audio/mp3 for .mp3 files
    • The following standards (and corresponding sample rates) are supported:
      • MPEG-1 layer 3 (48, 44.1, and 32 kHz)
      • MPEG-2 layer 3 (24, 22.05, and 16 kHz)
      • MPEG-2.5 layer 3 (12, 11.025, and 8 kHz)

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

NameDescription
audioUriThe URL of the audio file to play. May be a relative URL.

Attributes

ATTRIBUTEDescription
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 version="1.0" encoding="UTF-8"?>
<Response>
<PlayAudio>https://audio.url/audio1.wav</PlayAudio>
<PlayAudio>https://audio.url/audio2.mp3</PlayAudio>
</Response>