fix say verb should fallback to 2nd vendor if response_code is not 2xx

This commit is contained in:
Quan HL committed 2024-12-12 14:40:46 +07:00
1 parent c29ab0d858
commit d26b2383d8
1 file changed
+18 -1
+18 -1
View File
@@ -193,8 +193,25 @@ class TaskSay extends TtsTask {
}).catch((err) => this.logger.info({err}, 'Error adding file to cache'));
}
function extractResponseCode(evt) {
for (const key in evt) {
if (key.startsWith('variable_tts_') && key.endsWith('_response_code')) {
return evt[key];
}
}
return 0;
}
const response_code = extractResponseCode(evt);
if (this._playResolve) {
evt.variable_tts_error ? this._playReject(new Error(evt.variable_tts_error)) : this._playResolve();
//if tts vendor return bad response code or there is variable_tts_error,
// say task should reject the promise.
(response_code < 200 && response_code > 299 || evt.variable_tts_error) ?
this._playReject(
new Error(evt.variable_tts_error ||
`Synthesizing error, received ${evt.variable_tts_whisper_response_code} from vendor ${vendor}`)) :
this._playResolve();
}
});
// wait for playback-stop event received to confirm if the playback is successful