Speech detection 🔗

Speech detection works with a JavaScript library. This feature is not available in react-native for being a native implementation.

A pretty common requested event is one that allows you to detect when a publisher starts and stops speaking. OpenVidu offers this ability through PublisherSpeakingEvents that can be configured for Session objects:

session.on('publisherStartSpeaking', (event) => {
    console.log('Publisher ' + event.connection.connectionId + ' start speaking');
});

session.on('publisherStopSpeaking', (event) => {
    console.log('Publisher ' + event.connection.connectionId + ' stop speaking');
});

PublisherSpeakingEvents only apply to Subscribers. This means that publisherStartSpeaking and publisherStopSpeaking will only be triggered for remote Streams: those owned by a Subscriber object

You can further globally configure the behavior of these two events by using OpenVidu.setAdvancedConfiguration method:

var OV = new OpenVidu();
OV.setAdvancedConfiguration({
    publisherSpeakingEventsOptions: {
        interval: 100,   // Frequency of the polling of audio streams in ms (default 100)
        threshold: -50  // Threshold volume in dB (default -50)
    }
});

You can adjust dynamically this property for each specific Stream by using StreamManager.updatePublisherSpeakingEventsOptions method:

// 'streamManager' being a Publisher or Subscriber object
streamManager.updatePublisherSpeakingEventsOptions({
    interval: 100,   // Frequency of the polling of audio streams in ms
    threshold: -50  // Threshold volume in dB
});

With these events it is really easy to build a layout that can make the main speaker video the bigger one, and alternate the main view between the participants of a session as they take the floor.


Audio volume detection 🔗

Since release 2.7.0, you have also available a new StreamManagerEvent called streamAudioVolumeChange. You can get the audio volume (-100 being silence to 0 being max volume) of any Publisher or Subscriber by doing this:

publisher.on('streamAudioVolumeChange', (event) => {
    console.log('Publisher audio volume change from ' + event.value.oldValue + ' to' + event.value.newValue);
});

Event streamAudioVolumeChange will be triggered by both Subscriber and Publisher objects (while PublisherSpeakingEvents only work with Subscriber objects). By working fine with Publisher objects, you can for example build a volume meter to inform your users that their microphone is working ok, showing the volume being received by the input device.

The frequency streamAudioVolumeChange event is fired with is defined by property interval of OpenVidu.setAdvancedConfiguration (default 100ms). You can also adjust these values for each specific Publisher or Subscriber object with method StreamManager.updatePublisherSpeakingEventsOptions