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 in Session object:

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

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

It can also be configured for specific Publishers or Subscribers objects, if you are interested just in certain streams:

publisher.on('publisherStartSpeaking', (event) => {
    console.log('The local user start speaking');

subscriber.on('publisherStopSpeaking', (event) => {
    console.log('User ' + event.connection.connectionId + ' stop speaking');

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

var OV = new OpenVidu();
    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
    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 🔗

There is available a 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);

With event streamAudioVolumeChange you can easily 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