Hi guys, I’m learning mediasoup with the MiroTalk project, recently I introduced the monitoring of the participant’s audio volume to view the active ones. What I have done is add the producer (kind=audio) to audioLevelObserver.
if (kind === 'audio') {
roomList.get(socket.room_id).addProducerToAudioLevelObserver({ producerId: producer_id });
}
And then every 800ms (interval) if got on the event audioLevelObserver.on(‘volumes’…) I check what peers have audio enabled and then I notify all the peers about his volume.
AudioLevelObserver and ActiveSpeakerObserver are usually for the server-side logic. For the clients, it is probably better to use client API like getSynchronizationSources → audioLevel.
I was implementing AudioObservation using AudioLevelObserver and ActiveSpeakerObserver.
My Goal
Sending a map of last n active users to the frontend
Calculating the dominant speaker among them
Just curious to know if adding two observers - AudioLevelObserver & ActiveSpeakerObserver would be inefficient in any way.
Shall i just use AudioLevelObserver to calculate both the dominantSpeaker and the lastN peers or is it alright to use both ALO and ASO together for the two different requirements - lastN and dominantSpeaker respectively.
ActiveSpeakerObserver should be enough in your use-case to detect the dominant speaker. You mentioned to send the data to the peers what is the purpose of it? if you just want to show who is speaking or not then it is best to do it on client side.
It is better to create new topic, as this topic is quite old now.
In my application I show green border around the box of person who is speaking to highlight it totally on the client side without the involvement of the server using this library: GitHub - latentflip/hark: Converts an audio stream to speech events in the browser. As we have streams on our app side we can do lots to stuff with them without server’s involvement,
You can achieve the same using AudioLevelObserver, ActiveSpeakerObserver on the server side and emit socket events to the participants about who is speaking on not so that they update their UI. But that uses server’s resources and constant pinging to all the participants, why involving server if we can do all that on client side?
AudioLevelObserver, ActiveSpeakerObserver can be used on server side for a lot other purposes like if you want to detect if person is speaking or not and when he is not speaking means he is not active speaker you want to pause the consumers to minimise load on server and the network traffic as well.
These are just 2 use-cases, there can be any use-case.