gather/config: bargein fixes

This commit is contained in:
Dave Horton
2022-03-09 13:34:57 -05:00
parent d00ea5c95f
commit 7188648d3b
2 changed files with 25 additions and 12 deletions

View File

@@ -15,17 +15,17 @@ class TaskConfig extends Task {
if (this.hasBargeIn && this.bargeIn.enable === true) { if (this.hasBargeIn && this.bargeIn.enable === true) {
this.gatherOpts = { this.gatherOpts = {
verb: 'gather', verb: 'gather',
timeout: 0 timeout: 0,
bargein: true
}; };
[ [
'finishOnKey', 'input', 'numDigits', 'minDigits', 'maxDigits', 'finishOnKey', 'input', 'numDigits', 'minDigits', 'maxDigits',
'interDigitTimeout', 'dtmfBargein', 'actionHook' 'interDigitTimeout', 'bargein', 'dtmfBargein', 'minBargeinWordCount', 'actionHook'
].forEach((k) => { ].forEach((k) => {
if (this.bargeIn[k]) this.gatherOpts[k] = this.bargeIn[k]; if (this.bargeIn[k]) this.gatherOpts[k] = this.bargeIn[k];
}); });
this.preconditions = this.hasBargeIn ? TaskPreconditions.Endpoint : TaskPreconditions.None;
} }
this.preconditions = this.hasBargeIn ? TaskPreconditions.Endpoint : TaskPreconditions.None;
} }
get name() { return TaskName.Config; } get name() { return TaskName.Config; }

View File

@@ -9,7 +9,7 @@ const {
const makeTask = require('./make_task'); const makeTask = require('./make_task');
const assert = require('assert'); const assert = require('assert');
const GATHER_STABILITY_THRESHOLD = Number(process.env.JAMBONZ_GATHER_STABILITY_THRESHOLD || 0.7); //const GATHER_STABILITY_THRESHOLD = Number(process.env.JAMBONZ_GATHER_STABILITY_THRESHOLD || 0.7);
class TaskGather extends Task { class TaskGather extends Task {
constructor(logger, opts, parentTask) { constructor(logger, opts, parentTask) {
@@ -29,6 +29,7 @@ class TaskGather extends Task {
this.timeout = this.timeout === 0 ? 0 : (this.timeout || 15) * 1000; this.timeout = this.timeout === 0 ? 0 : (this.timeout || 15) * 1000;
this.interim = this.partialResultHook || this.bargein; this.interim = this.partialResultHook || this.bargein;
this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true; this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true;
this.minBargeinWordCount = this.data.minBargeinWordCount || 0;
if (this.data.recognizer) { if (this.data.recognizer) {
const recognizer = this.data.recognizer; const recognizer = this.data.recognizer;
this.vendor = recognizer.vendor; this.vendor = recognizer.vendor;
@@ -41,8 +42,6 @@ class TaskGather extends Task {
const {enable, voiceMs = 0, mode = -1} = recognizer.vad || {}; const {enable, voiceMs = 0, mode = -1} = recognizer.vad || {};
this.vad = {enable, voiceMs, mode}; this.vad = {enable, voiceMs, mode};
this.minBargeinWordCount = this.data.minBargeinWordCount || 0;
/* aws options */ /* aws options */
this.vocabularyName = recognizer.vocabularyName; this.vocabularyName = recognizer.vocabularyName;
this.vocabularyFilterName = recognizer.vocabularyFilterName; this.vocabularyFilterName = recognizer.vocabularyFilterName;
@@ -271,7 +270,11 @@ class TaskGather extends Task {
} }
_startTranscribing(ep) { _startTranscribing(ep) {
this.logger.debug('Gather:_startTranscribing'); this.logger.debug({
vendor: this.vendor,
locale: this.language,
interim: this.interim
}, 'Gather:_startTranscribing');
ep.startTranscription({ ep.startTranscription({
vendor: this.vendor, vendor: this.vendor,
locale: this.language, locale: this.language,
@@ -303,6 +306,15 @@ class TaskGather extends Task {
} }
_killAudio(cs) { _killAudio(cs) {
if (!this.sayTask && !this.playTask && this.bargein) {
if (this.ep?.connected && !this.playComplete) {
this.logger.debug('Gather:_killAudio: killing playback of any audio');
this.playComplete = true;
this.ep.api('uuid_break', this.ep.uuid)
.catch((err) => this.logger.info(err, 'Error killing audio'));
}
return;
}
if (this.sayTask && !this.sayTask.killed) { if (this.sayTask && !this.sayTask.killed) {
this.sayTask.removeAllListeners('playDone'); this.sayTask.removeAllListeners('playDone');
this.sayTask.kill(cs); this.sayTask.kill(cs);
@@ -348,11 +360,13 @@ class TaskGather extends Task {
https://cloud.google.com/speech-to-text/docs/basics#streaming_responses https://cloud.google.com/speech-to-text/docs/basics#streaming_responses
others do not. others do not.
*/ */
const isStableEnough = typeof evt.stability === 'undefined' || evt.stability > GATHER_STABILITY_THRESHOLD; //const isStableEnough = typeof evt.stability === 'undefined' || evt.stability > GATHER_STABILITY_THRESHOLD;
if (this.bargein && isStableEnough && if (this.bargein && /* isStableEnough && */
evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) { evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) {
this.logger.debug('Gather:_onTranscription - killing audio due to speech bargein'); if (!this.playComplete) {
this.logger.debug({transcript: evt.alternatives[0].transcript}, 'killing audio due to speech');
}
this._killAudio(cs); this._killAudio(cs);
} }
if (this.partialResultHook) { if (this.partialResultHook) {
@@ -363,7 +377,6 @@ class TaskGather extends Task {
_onEndOfUtterance(cs, ep) { _onEndOfUtterance(cs, ep) {
this.logger.info('TaskGather:_onEndOfUtterance'); this.logger.info('TaskGather:_onEndOfUtterance');
if (this.bargein && this.minBargeinWordCount === 0) { if (this.bargein && this.minBargeinWordCount === 0) {
this.logger.debug('Gather:_onTranscription - killing audio due to utterance detected');
this._killAudio(cs); this._killAudio(cs);
} }