This guide introduces the Dominant Speaker Detection API and provides guidance on how to use it effectively in your Twilio Video applications.
In a multi-party video application, the dominant speaker is the Participant sharing the loudest audio track in the Room. The Dominant Speaker Detection API sends events to your application every time the dominant speaker changes. Developers can use those events to improve the end user's experience by bringing into focus the speakers published video tracks.
The Room.dominantSpeaker
property (Android, (iOS, JavaScript) represents the RemoteParticipant with the loudest RemoteAudioTrack. Whenever the Dominant Speaker changes, the Room emits a dominantSpeakerChanged
event.
Note: dominantSpeakerChanged
events are emitted in Rooms with two or more Participants.
The Dominant Speaker API is disabled by default, and is requested at connect time. The following table illustrates the currently supported platforms:
Twilio Video SDK | Dominant Speaker API support |
---|---|
Android | Yes (v4.3.0+) |
iOS | Yes (v2.8.0+) |
JavaScript | Yes (v1.14.0+) |
When building ConnectOptions
, set the property enableDominantSpeaker
to true
.
1ConnectOptions connectOptions =2new ConnectOptions.Builder(token)3.roomName(roomName)4.enableDominantSpeaker(true)5.build();6Room room = Video.connect(context, connectOptions, roomListener);
Implement Room.Listener#onDominantSpeakerChanged(@NonNull Room room, @Nullable RemoteParticipant remoteParticipant) in order to respond to speaker events.
1@Override2void onDominantSpeakerChanged(3@NonNull Room room, @Nullable RemoteParticipant remoteParticipant) {4// Handle dominant speaker change5}
When building TVIConnectOptions
, set the property isDominantSpeakerEnabled
to true
.
1let connectOptions = ConnectOptions(token: accessToken) { (builder) in2// Enable Dominant Speaker functionality3builder.isDominantSpeakerEnabled = true45if let localAudioTrack = self.localAudioTrack {6builder.audioTracks = [localAudioTrack]7}8builder.roomName = "my-conference-room"9}1011room = TwilioVideoSDK.connect(options: connectOptions, delegate: self)
Implement -[TVIRoomDelegate room:dominantSpeakerDidChange:] in order to respond to speaker events.
1// MARK: TVIRoomDelegate2func dominantSpeakerDidChange(room: Room, participant: RemoteParticipant?) {3var identity = "N/A"45if let participant = participant {6identity = participant.identity7}89print("Dominant Speaker Changed: \(identity)")10}
In the connect
method, set the property dominantSpeaker
to true
to enable the Dominant Speaker API and to start receiving dominantSpeakerChanged
events.
1var Video = require('twilio-video');2var token = getAccessToken();34// Connect with custom names for LocalAudioTrack and LocalVideoTrack5Video.connect(token, {6name: 'my-conference-room'7audio: { name: 'microphone' },8video: { name: 'camera' },9dominantSpeaker: true10}).then(function(room) {11room.on('dominantSpeakerChanged', participant => {12console.log('The new dominant speaker in the Room is:', participant);13});14});