SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

Twilio Voice SDKs Supported Audio Codecs

Javascript Voice SDK

Twilio supports Opus and PCMU for our Voice SDKs which includes the Javascript SDK for browser-based VoIP applications and the android and iOS SDKs for mobile applications.

Which codec should you use?

The Opus codec has many advantages over PCMU and is recommended for most applications. Opus is the default codec for Mobile SDKs.

Network bandwidth requirements for the Voice SDKs

The following table lists the network requirements to deliver reasonable audio quality.

Bandwidth (Uplink/Downlink)

Opus*: 40kbps / 40kbps

PCMU: 100kbps / 100kbps

Latency (RTT)

< 200ms

Jitter

< 30ms

Packet Loss

< 3%

* Opus codec is available from Voice JavaScript SDK version 1.7 and Mobile Voice SDKs 3.x

The Opus bandwidth requirements listed above are the default settings for Opus. Opus codec supports bandwidth control by allowing you to specify how much bandwidth it should use.

More info on the OPUS codec

Opus codec supports bandwidth control by allowing you to specify how much bandwidth it should use.

The parameter to use with Opus to control the bandwidth is maxAverageBitrate.

The `maxAverageBitrate` parameter indicates the maximum average audio bitrate to use, in bits per second (bps) . By default, the setting is not used. If you specify 0, then the setting is not used. Any positive integer is allowed, but values outside the range 6000 to 510000 are ignored and treated as 0. The recommended bitrate for speech is between 8000 and 40000 bps. 

How to use the Opus codec in your web/browser VoIP app (Javascript SDK)

To use Opus in your web application, use the following snippet when either instantiating the Twilio.Device or updating the Twilio.Device’s options with .updateOptions(options):

const device = new Twilio.Device(token, { codecPreferences: ['opus', 'pcmu']});
// or
const device = new Twilio.Device(token);
device.updateOptions({ codecPreferences: ['opus', 'pcmu']});

To set a custom bandwidth (16kbps), use the following snippet:

const device = new Twilio.Device(token, { codecPreferences: ['opus', 'pcmu'], maxAverageBitrate: 16000} );
// or
const device = new Twilio.Device(token);
device.updateOptions({ codecPreferences: ['opus', 'pcmu'], maxAverageBitrate: 16000});  

Reference information:

https://www.twilio.com/docs/voice/sdks/network-connectivity-requirements#network-bandwidth-requirements 

https://www.twilio.com/docs/voice/sdks/javascript/twiliodevice#deviceoptions

https://www.twilio.com/docs/voice/sdks/network-connectivity-requirements#use-the-opus-codec-to-control-bandwidth-requirements 

https://www.twilio.com/docs/voice/sdks/network-connectivity-requirements#recommendations-and-best-practices 

Have more questions? Submit a request
Powered by Zendesk