Announcing Twilio Client JS SDK 1.7 GA with Opus Codec Support and Codec Preference API

April 03, 2019
Written by
Aymen Naim
Twilion

Programmable Voice iOS SDK

We’re excited to announce the General Availability of Twilio Client JS 1.7. With this release, Opus, a highly performant codec delivering better audio quality in various network environments, is now supported through the new Codec Preference API.

Compared to G.711 (PCMU), the other codec currently supported by Twilio Client JS, Opus delivers a superior voice quality at less than half the bandwidth (around 40kb/s as opposed to 80kb/s). We highly recommend enabling Opus in your applications to deliver this superior voice quality to your users.

Please refer to our changelog to find download instructions and API documentation.

Getting the Release and Upgrade Path

Upgrading from 1.3, 1.4, 1.5 and 1.6 is super simple. There are no breaking changes and it’s a matter of updating your twilio.js.

CDN URL

https://media.twiliocdn.com/sdk/js/client/v1.7/twilio.min.js

https://media.twiliocdn.com/sdk/js/client/v1.7/twilio.js

NPM

npm install --save twilio-client@^1.7.0

Codec Preference API

The Codec Preference API is a new and simple API that allows you to control which codecs you would like to use, and which one is your preferred.  With this release, G.711 (PCMU) will continue to be the default codec. This is primarily to leave you in control of when to roll out Opus. However, in a future major version release, we plan to make Opus the default codec. The following code example illustrates how to set Opus as the preferred codec.

 var device;
 // Setup Twilio.Device
 device = new Twilio.Device(YOUR_TOKEN, {
codecPreferences: ['opus', 'pcmu'] });
 var params = {
     To: “5105557777”
   };
 device.connect(params);

What is a Codec and what is the significance of Opus?

A codec is a formalised algorithm for coding and decoding data. In the case of VoIP, on the sender side, the analog voice signal is digitized, coded and streamed to the receiver.  At the receiver’s end, the coded stream is then decoded and converted back to an analog signal, amplified and played back to the receiver.

Codec role in media transmission

Codec role in media transmission.png

There are many codecs available today with each having a set of attributes or features. These include:

  • Bitrate - how much bandwidth it requires to function correctly
  • Dynamic bitrate - the ability to reduce or increase the bitrate dynamically, usually in response to changes in the available bandwidth and network quality
  • Packet Loss Concealment and Forward Error Correction - ability to handle and fill in the gaps in the event packets are lost
  • Voice Activity Detection - stops sending packets when there’s silence
  • Computation requirements - how complicated is it to encode and to decode. Complex codecs are not suitable for mobile applications
  • And many others

Most often, a codec is designed to deliver a certain quality for a given bandwidth range.  The most common design variable usually revolves around the trade-off of quality and bandwidth requirements - i.e. more bandwidth is required for higher quality voice transmissions.

MOS, Mean Opinion Score, is a measure used to rate a codec performance. MOS is usually determined subjectively by running experiments and letting users rate the sound quality. MOS can also be approximated by taking into account various variables including packet loss, jitter and bit rate. MOS scores range between 1 (unacceptable) and 5 (excellent).

So, what’s the significance of Opus?

Opus’ most compelling feature is the audio quality it can deliver under a wide range of network bandwidth availability. This can be seen in the diagram below.

Opus Codec Comparison

Opus Codec Comparison

As mentioned earlier,  G.711 (PCMU), another popular codec, is the only other codec supported by Twilio Client and as can be seen, for the same bandwidth requirements as G.711, Opus is able to deliver much higher audio quality. When bandwidth is reduced, G.711 based calls will degrade significantly whereas Opus continues to deliver very acceptable audio quality.

With that in mind, we recommend that all Twilio Client JS users upgrade to this new release and enable Opus to give your end users the best call quality possible. We can't wait to see what you build!