From 4855fec4f5b7a626cff4539df55433a4b0ae3128 Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Tue, 15 Feb 2022 13:55:18 +0100 Subject: [PATCH] add vad --- lib/tasks/gather.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index f801e6da..a150056f 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -44,6 +44,10 @@ class TaskGather extends Task { this.profanityOption = recognizer.profanityOption || 'raw'; this.requestSnr = recognizer.requestSnr || false; this.initialSpeechTimeoutMs = recognizer.initialSpeechTimeoutMs || 0; + + /* vad: if provided, we dont connect to recognizer until voice activity is detected */ + const {enable, voiceMs = 0, mode = -1} = recognizer.vad || {}; + this.vad = {enable, voiceMs, mode}; } this.digitBuffer = ''; @@ -197,7 +201,11 @@ class TaskGather extends Task { async _initSpeech(cs, ep) { const opts = {}; - + if (this.vad.enable) { + opts.START_RECOGNIZING_ON_VAD = 1; + if (this.vad.voiceMs) opts.RECOGNIZER_VAD_VOICE_MS = this.vad.voiceMs; + if (this.vad.mode >= 0 && this.vad.mode <= 3) opts.RECOGNIZER_VAD_MODE = this.vad.mode; + } if ('google' === this.vendor) { if (this.sttCredentials) opts.GOOGLE_APPLICATION_CREDENTIALS = JSON.stringify(this.sttCredentials.credentials); Object.assign(opts, {