Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Detecting the Dominant Speaker

This guide introduces the Dominant Speaker Detection API and provides guidance on how to use it effectively in your Twilio Video applications. The Dominant Speaker API is only available in Group Rooms.

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.

API Usage

The Room.dominantSpeaker property (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 Group Rooms with 2 or more Participants.

Enabling Dominant Speaker Detection

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 (Group Rooms)
Android Coming soon
iOS Yes (v2.8.0+)
JavaScript Yes (v1.14.0+)

iOS

When building TVIConnectOptions, set the property isDominantSpeakerEnabled to true.

let options = TVIConnectOptions(token: accessToken) { (builder) in

    // Enable Dominant Speaker functionality
    builder.isDominantSpeakerEnabled = true

    if let localAudioTrack = self.localAudioTrack {
        builder.audioTracks = [localAudioTrack]
    }
    builder.roomName = "my-conference-room"
}

room = TwilioVideo.connect(with: options, delegate: self)

Implement -[TVIRoomDelegate room:dominantSpeakerDidChange:] in order to respond to speaker events.

// MARK: TVIRoomDelegate
func room(_ room: TVIRoom, dominantSpeakerDidChange participant: TVIRemoteParticipant?) {
    var identity = "N/A"

    if let participant = participant {
        identity = participant.identity
    }

    print("Dominant Speaker Changed: \(identity)")
}

JavaScript

In the connect method, set the property dominantSpeaker to true to enable the Dominant Speaker API and to start receiving dominantSpeakerChanged events.

var Video = require('twilio-video');
var token = getAccessToken();

// Connect with custom names for LocalAudioTrack and LocalVideoTrack
Video.connect(token, {
  name: 'my-conference-room'
  audio: { name: 'microphone' },
  video: { name: 'camera' },
  dominantSpeaker: true
}).then(function(room) {
  room.on('dominantSpeakerChanged', participant => {
    console.log('The new dominant speaker in the Room is:', participant);
  });
});
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.