100ms Logo

100ms

Docs

Search docs
/

Show Audio Levels

Getting Audio Levels for all speaking peers

import 'package:hmssdk_flutter/hmssdk_flutter.dart'; void onUpdateSpeakers({required List<HMSSpeaker> updateSpeakers}){ // This is called every 1 second with list of active speakers }

Here are the properties on the HMSSpeaker class:

  1. audioLevel : int -> The level of the audio. It may vary from 0-100. A higher value indicates a higher speaking volume.
  2. track : HMSTrack -> The audio track corresponding to this speaker. It may be null when the speaker who was speaking loudly, leaves.
  3. peer : HMSPeer -> The peer who was speaking. This may be null if the peer has left before the update information has reached the other person.

Active Speaker Views

To maintain an active speaker view, such as the default view in the open source advanced sample app, you need to keep track of who the active speakers are over time. We'll be using the input from onUpdateSpeakers listener update as mentioned above and then building something that attempts to show all the active speakers while minimizing re-ordering the list.

Dominant Speaker - the loudest speaker.

The dominant speaker is the speaker who's the loudest at any given moment. There's a callback for this in the onPeerUpdate callback for HMSUpdateListener.

Here's the method signature for onPeerUpdate: void onPeerUpdate({required HMSPeer peer, required HMSPeerUpdate update})

When the dominant speaker has changed, there will be updates of the type:

HMSPeerUpdate.becameDominantSpeaker When a new person becomes the dominant speaker.

HMSPeerUpdate.noDominantSpeaker When the current dominant speaker stops talking and there's no one to replace them.