From 418baa20df00716ddf4d6e821d4852b0595077d0 Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Fri, 4 Feb 2022 08:12:53 +0100 Subject: [PATCH] fix setting initial config --- lib/tasks/cognigy/index.js | 28 +++++++++++++--------------- lib/tasks/cognigy/speech-config.js | 21 +++++++++------------ lib/tasks/gather.js | 12 +++++++----- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/lib/tasks/cognigy/index.js b/lib/tasks/cognigy/index.js index 3f8add62..ca88d443 100644 --- a/lib/tasks/cognigy/index.js +++ b/lib/tasks/cognigy/index.js @@ -99,21 +99,19 @@ class Cognigy extends Task { await super.exec(cs); const opts = { - session: { - synthesizer: this.data.synthesizer || { - vendor: 'default', - language: 'default', - voice: 'default' - }, - recognizer: this.data.recognizer || { - vendor: 'default', - language: 'default' - }, - bargein: this.data.bargein || {}, - bot: this.data.bot || {}, - user: this.data.user || {}, - dtmf: this.data.dtmf || {} - } + synthesizer: this.data.synthesizer || { + vendor: 'default', + language: 'default', + voice: 'default' + }, + recognizer: this.data.recognizer || { + vendor: 'default', + language: 'default' + }, + bargein: this.data.bargein || {}, + bot: this.data.bot || {}, + user: this.data.user || {}, + dtmf: this.data.dtmf || {} }; this.config = new SpeechConfig({logger: this.logger, ep, opts}); this.ep = ep; diff --git a/lib/tasks/cognigy/speech-config.js b/lib/tasks/cognigy/speech-config.js index e112136c..46482045 100644 --- a/lib/tasks/cognigy/speech-config.js +++ b/lib/tasks/cognigy/speech-config.js @@ -7,9 +7,6 @@ const stripNulls = (obj) => { return obj; }; - -const defaultSpeechConfig - class SpeechConfig extends Emitter { constructor({logger, ep, opts = {}}) { super(); @@ -19,16 +16,16 @@ class SpeechConfig extends Emitter { this.update(opts); } - _mergeConfig(changedConfig = {}){ + _mergeConfig(changedConfig = {}) { const merged = lodash.merge( - {}, - this.sessionConfig, - changedConfig - ); - merged.bargein.enable = changedConfig.bargein?.enable?.length === 0 ? [] : changedConfig.bargein?.enable; - this.logger.debug({merged, sessionConfig: this.sessionConfig, changedConfig}, 'merged config'); - // should we override hints with empty array or leave it as it is once saved? - // merged.recognizer.hints = changedConfig.recognizer?.hints + {}, + this.sessionConfig, + changedConfig + ); + merged.bargein.enable = changedConfig.bargein?.enable?.length === 0 ? [] : changedConfig.bargein?.enable; + this.logger.debug({merged, sessionConfig: this.sessionConfig, changedConfig}, 'merged config'); + // should we override hints with empty array or leave it as it is once saved? + // merged.recognizer.hints = changedConfig.recognizer?.hints } update(session) { diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 43c9eb51..0999d6c3 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -130,10 +130,10 @@ class TaskGather extends Task { else startListening(cs, ep); if (this.input.includes('speech') && this.listenDuringPrompt) { - await this._initSpeech(cs, ep); - this._startTranscribing(ep); - updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) - .catch(() => {/*already logged error */}); + await this._initSpeech(cs, ep); + this._startTranscribing(ep); + updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) + .catch(() => {/*already logged error */}); } if (this.input.includes('digits') || this.dtmfBargein) { @@ -318,7 +318,9 @@ class TaskGather extends Task { } if (evt.is_final) this._resolve('speech', evt); else { - if (evt.stability > 0.70 && this.bargein && evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) { + if (evt.stability > 0.70 && + this.bargein && + evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) { this.logger.debug('Gather:_onTranscription - killing audio due to bargein'); this._killAudio(cs); this._resolve('speech', evt);