fix setting initial config

This commit is contained in:
akirilyuk
2022-02-04 08:12:53 +01:00
parent eb418a42e9
commit 418baa20df
3 changed files with 29 additions and 32 deletions

View File

@@ -99,21 +99,19 @@ class Cognigy extends Task {
await super.exec(cs); await super.exec(cs);
const opts = { const opts = {
session: { synthesizer: this.data.synthesizer || {
synthesizer: this.data.synthesizer || { vendor: 'default',
vendor: 'default', language: 'default',
language: 'default', voice: 'default'
voice: 'default' },
}, recognizer: this.data.recognizer || {
recognizer: this.data.recognizer || { vendor: 'default',
vendor: 'default', language: 'default'
language: 'default' },
}, bargein: this.data.bargein || {},
bargein: this.data.bargein || {}, bot: this.data.bot || {},
bot: this.data.bot || {}, user: this.data.user || {},
user: this.data.user || {}, dtmf: this.data.dtmf || {}
dtmf: this.data.dtmf || {}
}
}; };
this.config = new SpeechConfig({logger: this.logger, ep, opts}); this.config = new SpeechConfig({logger: this.logger, ep, opts});
this.ep = ep; this.ep = ep;

View File

@@ -7,9 +7,6 @@ const stripNulls = (obj) => {
return obj; return obj;
}; };
const defaultSpeechConfig
class SpeechConfig extends Emitter { class SpeechConfig extends Emitter {
constructor({logger, ep, opts = {}}) { constructor({logger, ep, opts = {}}) {
super(); super();
@@ -19,16 +16,16 @@ class SpeechConfig extends Emitter {
this.update(opts); this.update(opts);
} }
_mergeConfig(changedConfig = {}){ _mergeConfig(changedConfig = {}) {
const merged = lodash.merge( const merged = lodash.merge(
{}, {},
this.sessionConfig, this.sessionConfig,
changedConfig changedConfig
); );
merged.bargein.enable = changedConfig.bargein?.enable?.length === 0 ? [] : changedConfig.bargein?.enable; merged.bargein.enable = changedConfig.bargein?.enable?.length === 0 ? [] : changedConfig.bargein?.enable;
this.logger.debug({merged, sessionConfig: this.sessionConfig, changedConfig}, 'merged config'); 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? // should we override hints with empty array or leave it as it is once saved?
// merged.recognizer.hints = changedConfig.recognizer?.hints // merged.recognizer.hints = changedConfig.recognizer?.hints
} }
update(session) { update(session) {

View File

@@ -130,10 +130,10 @@ class TaskGather extends Task {
else startListening(cs, ep); else startListening(cs, ep);
if (this.input.includes('speech') && this.listenDuringPrompt) { if (this.input.includes('speech') && this.listenDuringPrompt) {
await this._initSpeech(cs, ep); await this._initSpeech(cs, ep);
this._startTranscribing(ep); this._startTranscribing(ep);
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid)
.catch(() => {/*already logged error */}); .catch(() => {/*already logged error */});
} }
if (this.input.includes('digits') || this.dtmfBargein) { if (this.input.includes('digits') || this.dtmfBargein) {
@@ -318,7 +318,9 @@ class TaskGather extends Task {
} }
if (evt.is_final) this._resolve('speech', evt); if (evt.is_final) this._resolve('speech', evt);
else { 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.logger.debug('Gather:_onTranscription - killing audio due to bargein');
this._killAudio(cs); this._killAudio(cs);
this._resolve('speech', evt); this._resolve('speech', evt);