Skip to contentSkip to navigationSkip to topbar
On this page

Specify Audio and Video Constraints in JavaScript


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).

1
const { connect, createLocalAudioTrack, createLocalTracks } = require('twilio-video');
2
3
// Option 1
4
createLocalTracks({
5
audio: { noiseSuppression: false, echoCancellation: false },
6
video: true
7
}).then(localTracks => {
8
return connect('$TOKEN', {
9
name: 'my-room-name',
10
tracks: localTracks
11
});
12
}).then(room => {
13
console.log(`Connected to Room: ${room.name}`);
14
});
15
16
// Option 2
17
connect('$TOKEN', {
18
audio: { noiseSuppression: false, echoCancellation: false },
19
name: 'my-room-name',
20
video: true
21
}).then(room => {
22
console.log(`Connected to Room: ${room.name}`);
23
});
24
25
// Option 3
26
createLocalAudioTrack({
27
noiseSuppression: false,
28
echoCancellation: false
29
}).then(localTrack => {
30
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.

1
const { connect, createLocalTracks } = require('twilio-video');
2
3
// Option 1
4
createLocalTracks({
5
audio: true,
6
video: { width: 640 },
7
}).then(localTracks => {
8
return connect('$TOKEN', {
9
name: 'my-room-name',
10
tracks: localTracks,
11
});
12
}).then(room => {
13
console.log(`Connected to Room: ${room.name}`);
14
});
15
16
// Option 2
17
connect('$TOKEN', {
18
audio: true,
19
name: 'my-room-name',
20
video: { width: 640 },
21
}).then(room => {
22
console.log(`Connected to Room: ${room.name}`);
23
});

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.