|
@@ -1,6 +1,8 @@
|
1
|
1
|
import { EventEmitter } from 'events';
|
2
|
|
-import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
|
3
|
2
|
import { getLogger } from 'jitsi-meet-logger';
|
|
3
|
+
|
|
4
|
+import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
|
|
5
|
+
|
4
|
6
|
import { VAD_SCORE_PUBLISHED, VAD_TALK_WHILE_MUTED } from './DetectionEvents';
|
5
|
7
|
import TrackVADEmitter from './TrackVADEmitter';
|
6
|
8
|
|
|
@@ -79,7 +81,9 @@ export default class VADTalkMutedDetection extends EventEmitter {
|
79
|
81
|
*/
|
80
|
82
|
this._vadInitTracker = null;
|
81
|
83
|
|
82
|
|
-
|
|
84
|
+ /**
|
|
85
|
+ * Listens for {@link TrackVADEmitter} events and processes them.
|
|
86
|
+ */
|
83
|
87
|
this._processVADScore = this._processVADScore.bind(this);
|
84
|
88
|
|
85
|
89
|
/**
|
|
@@ -88,30 +92,6 @@ export default class VADTalkMutedDetection extends EventEmitter {
|
88
|
92
|
conference.on(JitsiConferenceEvents.TRACK_ADDED, this._trackAdded.bind(this));
|
89
|
93
|
conference.on(JitsiConferenceEvents.TRACK_REMOVED, this._trackRemoved.bind(this));
|
90
|
94
|
conference.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED, this._trackMuteChanged.bind(this));
|
91
|
|
-
|
92
|
|
- // TODO do we need to handle the case where tracks are removed, make sure this cleans up properly so
|
93
|
|
- // we don't have any leeks i.e. stale JitsiLocalTracks
|
94
|
|
- }
|
95
|
|
-
|
96
|
|
- /**
|
97
|
|
- * Determine if the current score is high enough that we should start the final score processing, and make sure
|
98
|
|
- * there isn't already a process operation ongoing.
|
99
|
|
- *
|
100
|
|
- * @param {number} score - PCM sample VAD score.
|
101
|
|
- * @return {boolean}
|
102
|
|
- */
|
103
|
|
- _shouldStartVADCompute(vadScore) {
|
104
|
|
- return vadScore > VAD_VOICE_LEVEL && !this._processing;
|
105
|
|
- }
|
106
|
|
-
|
107
|
|
- /**
|
108
|
|
- * Determine if the computed score over the configured timestamp should trigger an event.
|
109
|
|
- *
|
110
|
|
- * @param {number} computedScore - Computed VAD score.
|
111
|
|
- * @returns {boolean} - Should or shouldn't trigger.
|
112
|
|
- */
|
113
|
|
- _shouldTriggerNotification(computedScore) {
|
114
|
|
- return computedScore > VAD_AVG_THRESHOLD;
|
115
|
95
|
}
|
116
|
96
|
|
117
|
97
|
/**
|
|
@@ -139,15 +119,7 @@ export default class VADTalkMutedDetection extends EventEmitter {
|
139
|
119
|
* @returns {number} - Score average.
|
140
|
120
|
*/
|
141
|
121
|
_calculateAverage(scoreArray) {
|
142
|
|
- let avg = 0;
|
143
|
|
-
|
144
|
|
- if (scoreArray.length) {
|
145
|
|
- const sum = scoreArray.reduce((a, b) => a + b);
|
146
|
|
-
|
147
|
|
- avg = sum / scoreArray.length;
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- return avg;
|
|
122
|
+ return scoreArray.length > 0 ? scoreArray.reduce((a, b) => a + b) / scoreArray.length : 0;
|
151
|
123
|
}
|
152
|
124
|
|
153
|
125
|
/**
|
|
@@ -158,13 +130,7 @@ export default class VADTalkMutedDetection extends EventEmitter {
|
158
|
130
|
_calculateVADScore() {
|
159
|
131
|
const score = this._calculateAverage(this._scoreArray);
|
160
|
132
|
|
161
|
|
- if (this._shouldTriggerNotification(score)) {
|
162
|
|
- /**
|
163
|
|
- * User is talking while the mic is muted, generate event.
|
164
|
|
- *
|
165
|
|
- * @event VAD_TALK_WHILE_MUTED.
|
166
|
|
- * @type {Object}
|
167
|
|
- */
|
|
133
|
+ if (score > VAD_AVG_THRESHOLD) {
|
168
|
134
|
this.emit(VAD_TALK_WHILE_MUTED, {});
|
169
|
135
|
|
170
|
136
|
// Event was fired. Stop event emitter and remove listeners so no residue events kick off after this point
|
|
@@ -188,7 +154,7 @@ export default class VADTalkMutedDetection extends EventEmitter {
|
188
|
154
|
_processVADScore(vadScore) {
|
189
|
155
|
// Because we remove all listeners on the vadEmitter once the main event is triggered,
|
190
|
156
|
// there is no need to check for rogue events.
|
191
|
|
- if (this._shouldStartVADCompute(vadScore.score)) {
|
|
157
|
+ if (vadScore.score > VAD_VOICE_LEVEL && !this._processing) {
|
192
|
158
|
this._processing = true;
|
193
|
159
|
|
194
|
160
|
// Start gathering VAD scores for the configured period of time.
|