feat fallback speech

This commit is contained in:
Quan HL
2023-08-17 14:28:50 +07:00
parent b1c0478051
commit 5754c386d3
3 changed files with 16 additions and 16 deletions

View File

@@ -133,7 +133,7 @@ class Dialogflow extends Task {
this.fallbackVoice = cs.fallbackSpeechSynthesisVoice;
this.fallbackLabel = cs.fallbackSpeechSynthesisLabel;
}
this.ttsCredentials = cs.getSpeechCredentials(this.vendor, 'tts',this.speechSynthesisLabel);
this.ttsCredentials = cs.getSpeechCredentials(this.vendor, 'tts', this.speechSynthesisLabel);
this.ep.addCustomEventListener('dialogflow::intent', this._onIntent.bind(this, ep, cs));
this.ep.addCustomEventListener('dialogflow::transcription', this._onTranscription.bind(this, ep, cs));
@@ -235,7 +235,7 @@ class Dialogflow extends Task {
}
try {
const {filePath, servedFromCache} = await this.fallbackSynthAudio(cs, intent, stats);
const {filePath, servedFromCache} = await this.fallbackSynthAudio(cs, intent, stats, synthAudio);
if (filePath) cs.trackTmpFile(filePath);
if (!this.ttsCredentials && !servedFromCache) cs.billForTts(intent.fulfillmentText.length);
@@ -281,7 +281,7 @@ class Dialogflow extends Task {
}
}
async fallbackSynthAudio(cs, intent, stats) {
async fallbackSynthAudio(cs, intent, stats, synthAudio) {
try {
const obj = {
account_sid: cs.accountSid,
@@ -299,7 +299,7 @@ class Dialogflow extends Task {
this.logger.info({error}, 'Failed to synthesize audio from primary vendor');
try {
if(this.fallbackVendor) {
if (this.fallbackVendor) {
const credentials = cs.getSpeechCredentials(this.fallbackVendor, 'tts', this.fallbackLabel);
const obj = {
account_sid: cs.accountSid,
@@ -313,7 +313,7 @@ class Dialogflow extends Task {
this.logger.debug({obj}, 'Dialogflow:_onIntent - playing message via fallback tts');
return await synthAudio(stats, obj);
}
} catch(err) {
} catch (err) {
this.logger.info({err}, 'Failed to synthesize audio from falllback vendor');
throw err;
}