mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
Allow Say, Gather, Transcribe is able to finished if there is error for speech credential (#910)
* allow move to next task if say verb is failed because of speech credential * allow move to next task if say verb is failed because of speech credential * allow move to next task if say verb is failed because of speech credential * wip * wip
This commit is contained in:
@@ -22,6 +22,7 @@ const {
|
|||||||
const makeTask = require('./make_task');
|
const makeTask = require('./make_task');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const SttTask = require('./stt-task');
|
const SttTask = require('./stt-task');
|
||||||
|
const { SpeechCredentialError } = require('../utils/error');
|
||||||
|
|
||||||
class TaskGather extends SttTask {
|
class TaskGather extends SttTask {
|
||||||
constructor(logger, opts, parentTask) {
|
constructor(logger, opts, parentTask) {
|
||||||
@@ -122,7 +123,20 @@ class TaskGather extends SttTask {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(cs, {ep}) {
|
async exec(cs, obj) {
|
||||||
|
try {
|
||||||
|
await this.handling(cs, obj);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof SpeechCredentialError) {
|
||||||
|
this.logger.info('Gather failed due to SpeechCredentialError, finished!');
|
||||||
|
this.notifyTaskDone();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async handling(cs, {ep}) {
|
||||||
this.logger.debug({options: this.data}, 'Gather:exec');
|
this.logger.debug({options: this.data}, 'Gather:exec');
|
||||||
await super.exec(cs, {ep});
|
await super.exec(cs, {ep});
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const TtsTask = require('./tts-task');
|
const TtsTask = require('./tts-task');
|
||||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||||
const pollySSMLSplit = require('polly-ssml-split');
|
const pollySSMLSplit = require('polly-ssml-split');
|
||||||
|
const { SpeechCredentialError } = require('../utils/error');
|
||||||
|
|
||||||
const breakLengthyTextIfNeeded = (logger, text) => {
|
const breakLengthyTextIfNeeded = (logger, text) => {
|
||||||
const chunkSize = 1000;
|
const chunkSize = 1000;
|
||||||
@@ -61,7 +62,23 @@ class TaskSay extends TtsTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(cs, {ep}) {
|
async exec(cs, obj) {
|
||||||
|
try {
|
||||||
|
await this.handling(cs, obj);
|
||||||
|
this.emit('playDone');
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof SpeechCredentialError) {
|
||||||
|
// if say failed due to speech credentials, alarm is writtern and error notification is sent
|
||||||
|
// finished this say to move to next task.
|
||||||
|
this.logger.info('Say failed due to SpeechCredentialError, finished!');
|
||||||
|
this.emit('playDone');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async handling(cs, {ep}) {
|
||||||
const {srf, accountSid:account_sid, callSid:target_sid} = cs;
|
const {srf, accountSid:account_sid, callSid:target_sid} = cs;
|
||||||
const {writeAlerts, AlertType} = srf.locals;
|
const {writeAlerts, AlertType} = srf.locals;
|
||||||
const {addFileToCache} = srf.locals.dbHelpers;
|
const {addFileToCache} = srf.locals.dbHelpers;
|
||||||
@@ -117,7 +134,7 @@ class TaskSay extends TtsTask {
|
|||||||
} else {
|
} else {
|
||||||
this.notifyError(
|
this.notifyError(
|
||||||
{ msg: 'TTS error', details:`TTS vendor ${vendor} error: ${error}`, failover: 'not available'});
|
{ msg: 'TTS error', details:`TTS vendor ${vendor} error: ${error}`, failover: 'not available'});
|
||||||
throw error;
|
throw new SpeechCredentialError(error.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let filepath;
|
let filepath;
|
||||||
@@ -206,6 +223,7 @@ class TaskSay extends TtsTask {
|
|||||||
continue;
|
continue;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info({err}, 'Error waiting for playback-stop event');
|
this.logger.info({err}, 'Error waiting for playback-stop event');
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this._playPromise = null;
|
this._playPromise = null;
|
||||||
@@ -223,7 +241,6 @@ class TaskSay extends TtsTask {
|
|||||||
segment++;
|
segment++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.emit('playDone');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async kill(cs) {
|
async kill(cs) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const Task = require('./task');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { TaskPreconditions, CobaltTranscriptionEvents } = require('../utils/constants');
|
const { TaskPreconditions, CobaltTranscriptionEvents } = require('../utils/constants');
|
||||||
|
const { SpeechCredentialError } = require('../utils/error');
|
||||||
|
|
||||||
class SttTask extends Task {
|
class SttTask extends Task {
|
||||||
|
|
||||||
@@ -190,7 +191,7 @@ class SttTask extends Task {
|
|||||||
target_sid: cs.callSid
|
target_sid: cs.callSid
|
||||||
}).catch((err) => this.logger.info({err}, 'Error generating alert for no stt'));
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for no stt'));
|
||||||
// the ASR might have fallback configuration, should not done task here.
|
// the ASR might have fallback configuration, should not done task here.
|
||||||
throw new Error(`No speech-to-text service credentials for ${vendor} have been configured`);
|
throw new SpeechCredentialError(`No speech-to-text service credentials for ${vendor} have been configured`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vendor === 'nuance' && credentials.client_id) {
|
if (vendor === 'nuance' && credentials.client_id) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const {
|
|||||||
} = require('../utils/constants.json');
|
} = require('../utils/constants.json');
|
||||||
const { normalizeJambones } = require('@jambonz/verb-specifications');
|
const { normalizeJambones } = require('@jambonz/verb-specifications');
|
||||||
const SttTask = require('./stt-task');
|
const SttTask = require('./stt-task');
|
||||||
|
const { SpeechCredentialError } = require('../utils/error');
|
||||||
|
|
||||||
const STT_LISTEN_SPAN_NAME = 'stt-listen';
|
const STT_LISTEN_SPAN_NAME = 'stt-listen';
|
||||||
|
|
||||||
@@ -73,7 +74,20 @@ class TaskTranscribe extends SttTask {
|
|||||||
return this.channel === 2 || this.separateRecognitionPerChannel && this.ep2;
|
return this.channel === 2 || this.separateRecognitionPerChannel && this.ep2;
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(cs, {ep, ep2}) {
|
async exec(cs, obj) {
|
||||||
|
try {
|
||||||
|
await this.handling(cs, obj);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof SpeechCredentialError) {
|
||||||
|
this.logger.info('Transcribe failed due to SpeechCredentialError, finished!');
|
||||||
|
this.notifyTaskDone();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async handling(cs, {ep, ep2}) {
|
||||||
await super.exec(cs, {ep, ep2});
|
await super.exec(cs, {ep, ep2});
|
||||||
|
|
||||||
if (this.data.recognizer.vendor === 'nuance') {
|
if (this.data.recognizer.vendor === 'nuance') {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const Task = require('./task');
|
const Task = require('./task');
|
||||||
const { TaskPreconditions } = require('../utils/constants');
|
const { TaskPreconditions } = require('../utils/constants');
|
||||||
|
const { SpeechCredentialError } = require('../utils/error');
|
||||||
|
|
||||||
class TtsTask extends Task {
|
class TtsTask extends Task {
|
||||||
|
|
||||||
@@ -52,7 +53,8 @@ class TtsTask extends Task {
|
|||||||
|
|
||||||
let credentials = cs.getSpeechCredentials(vendor, 'tts', label);
|
let credentials = cs.getSpeechCredentials(vendor, 'tts', label);
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
throw new Error(`No text-to-speech service credentials for ${vendor} with labels: ${label} have been configured`);
|
throw new SpeechCredentialError(
|
||||||
|
`No text-to-speech service credentials for ${vendor} with labels: ${label} have been configured`);
|
||||||
}
|
}
|
||||||
/* parse Nuance voices into name and model */
|
/* parse Nuance voices into name and model */
|
||||||
let model;
|
let model;
|
||||||
@@ -124,7 +126,7 @@ class TtsTask extends Task {
|
|||||||
vendor,
|
vendor,
|
||||||
target_sid: cs.callSid
|
target_sid: cs.callSid
|
||||||
}).catch((err) => this.logger.info({err}, 'Error generating alert for no tts'));
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for no tts'));
|
||||||
throw new Error('no provisioned speech credentials for TTS');
|
throw new SpeechCredentialError('no provisioned speech credentials for TTS');
|
||||||
}
|
}
|
||||||
// synthesize all of the text elements
|
// synthesize all of the text elements
|
||||||
let lastUpdated = false;
|
let lastUpdated = false;
|
||||||
|
|||||||
9
lib/utils/error.js
Normal file
9
lib/utils/error.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class SpeechCredentialError extends Error {
|
||||||
|
constructor(msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
SpeechCredentialError
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user