Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Specify Audio and Video Constraints in JavaScript


(warning)

Warning

This documentation is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2026(link takes you to an external page).

We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide(link takes you to an external page) to assist you in minimizing any service disruption.

As you build with Twilio Video, you can customize certain aspects of your Participants' audio and video capture to optimize behavior for your specific use case. For example, you can turn on or off features such as noise suppression, or alter the video's frame rate. Below are examples for specifying audio and video constraints for local tracks.


Audio Constraints

audio-constraints page anchor

You can customize audio capture by setting audio constraints(link takes you to an external page) on a LocalAudioTrack(link takes you to an external page). Note that all the constraints default to true(link takes you to an external page).


_31
const { connect, createLocalAudioTrack, createLocalTracks } = require('twilio-video');
_31
_31
// Option 1
_31
createLocalTracks({
_31
audio: { noiseSuppression: false, echoCancellation: false },
_31
video: true
_31
}).then(localTracks => {
_31
return connect('$TOKEN', {
_31
name: 'my-room-name',
_31
tracks: localTracks
_31
});
_31
}).then(room => {
_31
console.log(`Connected to Room: ${room.name}`);
_31
});
_31
_31
// Option 2
_31
connect('$TOKEN', {
_31
audio: { noiseSuppression: false, echoCancellation: false },
_31
name: 'my-room-name',
_31
video: true
_31
}).then(room => {
_31
console.log(`Connected to Room: ${room.name}`);
_31
});
_31
_31
// Option 3
_31
createLocalAudioTrack({
_31
noiseSuppression: false,
_31
echoCancellation: false
_31
}).then(localTrack => {
_31
console.log(`Created LocalAudioTrack: ${localTrack.name}`);
_31
});


You can customize video capture by setting video constraints(link takes you to an external page) on a LocalVideoTrack(link takes you to an external page). Setting constraints lets you optimize the video track for network and device conditions. You can set the size, frame rate, or aspect ratio constraints of your choice. Note that all the constraints default to true(link takes you to an external page).

Please keep in mind that video constraints are used to resolve the video capture format, but the actual video sent to other Participants may be downscaled temporally or spatially in response to those Participants' network and device conditions.


_23
const { connect, createLocalTracks } = require('twilio-video');
_23
_23
// Option 1
_23
createLocalTracks({
_23
audio: true,
_23
video: { width: 640 },
_23
}).then(localTracks => {
_23
return connect('$TOKEN', {
_23
name: 'my-room-name',
_23
tracks: localTracks,
_23
});
_23
}).then(room => {
_23
console.log(`Connected to Room: ${room.name}`);
_23
});
_23
_23
// Option 2
_23
connect('$TOKEN', {
_23
audio: true,
_23
name: 'my-room-name',
_23
video: { width: 640 },
_23
}).then(room => {
_23
console.log(`Connected to Room: ${room.name}`);
_23
});


Rate this page: