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 (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 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 | Yes (v4.3.0+) |
iOS | Yes (v2.8.0+) |
JavaScript | Yes (v1.14.0+) |
Android
When building ConnectOptions
, set the property enableDominantSpeaker
to true
.
ConnectOptions connectOptions =
new ConnectOptions.Builder(token)
.roomName(roomName)
.enableDominantSpeaker(true)
.build();
Room room = Video.connect(context, connectOptions, roomListener);
Implement Room.Listener#onDominantSpeakerChanged(@NonNull Room room, @Nullable RemoteParticipant remoteParticipant) in order to respond to speaker events.
@Override
void onDominantSpeakerChanged(
@NonNull Room room, @Nullable RemoteParticipant remoteParticipant) {
// Handle dominant speaker change
}
iOS
When building TVIConnectOptions
, set the property isDominantSpeakerEnabled
to true
.
let connectOptions = ConnectOptions(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 = TwilioVideoSDK.connect(options: connectOptions, delegate: self)
Implement -[TVIRoomDelegate room:dominantSpeakerDidChange:] in order to respond to speaker events.
// MARK: TVIRoomDelegate
func dominantSpeakerDidChange(room: Room, participant: RemoteParticipant?) {
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);
});
});
Known Issues
- At present it is not possible to detect when a PSTN participant is the dominant speaker. A PSTN participant is one who dials a Twilio phone number and is connected to a Room using the Connect TwiML verb
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 by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.