How to implement voice activity detection for publisher?

Hi there! I am still evaluating OpenVidu. I have successfully implemented Push-To-Talk using the this.publisher.publishAudio(state); API.

Now I would like to have some kind of an API which would let me do:

if (publisher is speaking) {
   this.publisher.publishAudio(true);
} else {
   this.publisher.publishAudio(false);
}

Perhaps with some granular control over the activation volume. I found a module called hark (https://www.npmjs.com/package/hark) which seemed promising but I can’t make it to work.

const monitor = hark(this.publisher.stream.getMediaStream());
monitor.on('speaking', () => {
    console.log('Speaking');
});

monitor.on('stopped_speaking', () => {
    console.log('stopped_speaking');
});

Hi Rush,

The Hark library is used by openvidu-browser internally. Therefore you can use it for detect if some publisher is speaking through our Speech detection events https://docs.openvidu.io/en/2.16.0/advanced-features/speech-detection/#speech-detection

@CSantosM it seems this is for remote publishers only.

A workaround that you can use is the audio volume detection for your local publisher https://docs.openvidu.io/en/2.16.0/advanced-features/speech-detection/#audio-volume-detection