diff --git a/lib/tasks/say.js b/lib/tasks/say.js index f1d3ad3b..49a9d8d8 100644 --- a/lib/tasks/say.js +++ b/lib/tasks/say.js @@ -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