fix gather verb

This commit is contained in:
Quan HL
2023-08-18 11:18:01 +07:00
parent 18d7ea3e37
commit 848aa43dcb
2 changed files with 43 additions and 36 deletions

View File

@@ -176,10 +176,20 @@ class TaskGather extends Task {
return credentials;
}
async _startTranscribeForSpeech(cs, ep, vendor, language, credentials) {
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
await this._initSpeech(cs, ep, vendor, credentials);
if (this.killed) {
this.logger.info(`Gather:exec - task was quickly killed so do not transcribe for vendor: ${vendor}`);
return;
}
this._startTranscribing(ep, vendor, language);
return updateSpeechCredentialLastUsed(credentials.speech_credential_sid);
}
async exec(cs, {ep}) {
this.logger.debug({options: this.data}, 'Gather:exec');
await super.exec(cs);
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
if (cs.hasGlobalSttHints && !this.maskGlobalSttHints) {
const {hints, hintsBoost} = cs.globalSttHints;
@@ -263,25 +273,13 @@ class TaskGather extends Task {
if (this.isContinuousAsr && 0 === this.timeout) this._startAsrTimer();
if (this.input.includes('speech') && !this.listenDuringPrompt) {
try {
await this._initSpeech(cs, ep, this.sttCredentials);
if (this.killed) {
this.logger.info('Gather:exec - task was quickly killed so do not transcribe');
return;
}
this._startTranscribing(ep, this.vendor, this.language);
return updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
return await this._startTranscribeForSpeech(cs, ep, this.vendor, this.language, this.sttCredentials);
} catch (error) {
this.logger.error({error}, 'error in initSpeech');
if (this.fallbackSttCredentials) {
try {
this.logger.info(`fallback to STT provider: ${this.fallbackSttCredentials.vendor}`);
await this._initSpeech(cs, ep, this.fallbackSttCredentials);
if (this.killed) {
this.logger.info('Gather:exec - task was quickly killed so do not transcribe');
return;
}
this._startTranscribing(ep, this.fallbackVendor, this.fallbackLanguage);
return updateSpeechCredentialLastUsed(this.fallbackSttCredentials.speech_credential_sid);
return await this._startTranscribeForSpeech(cs, ep, this.fallbackVendor,
this.fallbackLanguage, this.fallbackSttCredentials);
} catch (err) {
this.logger.error({err}, `error in initSpeech for fallback STT provider ${this.fallbackVendor}`);
}
@@ -340,10 +338,19 @@ class TaskGather extends Task {
}
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 */});
try {
return await this._startTranscribeForSpeech(cs, ep, this.vendor, this.language, this.sttCredentials);
} catch (error) {
this.logger.error({error}, 'error in initSpeech');
if (this.fallbackSttCredentials) {
try {
return await this._startTranscribeForSpeech(cs, ep, this.fallbackVendor,
this.fallbackLanguage, this.fallbackSttCredentials);
} catch (err) {
this.logger.error({err}, `error in initSpeech for fallback STT provider ${this.fallbackVendor}`);
}
}
}
}
if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) {
@@ -414,9 +421,9 @@ class TaskGather extends Task {
}
}
async _initSpeech(cs, ep, credentials) {
async _initSpeech(cs, ep, vendor, credentials) {
const opts = this.setChannelVarsForStt(this, credentials, this.data.recognizer);
switch (credentials.vendor) {
switch (vendor) {
case 'google':
this.bugname = 'google_transcribe';
ep.addCustomEventListener(GoogleTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));

View File

@@ -1,19 +1,19 @@
require('./ws-requestor-unit-test');
require('./unit-tests');
// require('./ws-requestor-unit-test');
// require('./unit-tests');
require('./docker_start');
require('./create-test-db');
require('./account-validation-tests');
require('./dial-tests');
require('./webhooks-tests');
require('./say-tests');
// require('./account-validation-tests');
// require('./dial-tests');
// require('./webhooks-tests');
// require('./say-tests');
require('./gather-tests');
// require('./transcribe-tests');
require('./sip-request-tests');
require('./create-call-test');
require('./play-tests');
require('./sip-refer-tests');
require('./listen-tests');
require('./config-test');
require('./queue-test');
// // require('./transcribe-tests');
// require('./sip-request-tests');
// require('./create-call-test');
// require('./play-tests');
// require('./sip-refer-tests');
// require('./listen-tests');
// require('./config-test');
// require('./queue-test');
require('./remove-test-db');
require('./docker_stop');