Interface: NoiseCancellation

NoiseCancellation

NoiseCancellation interface provides methods to control noise cancellation at runtime. This interface is exposed on LocalAudioTrack property noiseCancellation. It is available only when NoiseCancellationOptions are specified when creating a LocalAudioTrack, and the plugin is successfully loaded.

Example

const { connect, createLocalAudioTrack } = require('twilio-video');

// Create a LocalAudioTrack with Krisp noise cancellation enabled.
const localAudioTrack = await createLocalAudioTrack({
  noiseCancellationOptions: {
    sdkAssetsPath: 'path/to/hosted/twilio/krisp/audio/plugin/1.0.0/dist',
    vendor: 'krisp'
  }
});

if (!localAudioTrack.noiseCancellation) {
  // If the Krisp audio plugin fails to load, then a warning message will be logged
  // in the browser console, and the "noiseCancellation" property will be set to null.
  // You can still use the LocalAudioTrack to join a Room. However, it will use the
  // browser's noise suppression instead of the Krisp noise cancellation. Make sure
  // the "sdkAssetsPath" provided in "noiseCancellationOptions" points to the correct
  // hosted path of the plugin assets.
} else {
  // Join a Room with the LocalAudioTrack.
  const room = await connect('token', {
    name: 'my-cool-room',
    tracks: [localAudioTrack]
  });

  if (!localAudioTrack.noiseCancellation.isEnabled) {
    // Krisp noise cancellation is permanently disabled in Peer-to-Peer and Go Rooms.
  }
}

//
// Enable/disable noise cancellation.
// @param {boolean} enable - whether noise cancellation should be enabled
//
function setNoiseCancellation(enable) {
  const { noiseCancellation } = localAudioTrack;
  if (noiseCancellation) {
    if (enable) {
      // If enabled, then the LocalAudioTrack will use the Krisp noise
      // cancellation instead of the browser's noise suppression.
      noiseCancellation.enable();
    } else {
      // If disabled, then the LocalAudioTrack will use the browser's
      // noise suppression instead of the Krisp noise cancellation.
      noiseCancellation.disable();
    }
  }
}

Members


isEnabled :boolean

Whether noise cancellation is enabled.

Type:
  • boolean

sourceTrack :MediaStreamTrack

The underlying MediaStreamTrack of the LocalAudioTrack.

Type:
  • MediaStreamTrack

vendor :NoiseCancellationVendor

Name of the noise cancellation vendor.

Type:

Methods


disable()

Disable noise cancellation.

Returns:

Promise that resolves when the operation is complete

Type
Promise.<void>

enable()

Enable noise cancellation.

Throws:

Throws an error if noise cancellation is disabled permanently for the LocalAudioTrack

Type
Error
Returns:

Promise that resolves when the operation is complete

Type
Promise.<void>