From 5ccea65b7f0e28ae58cf43dada40a5d6f53bec8e Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Wed, 10 Jul 2024 21:36:00 +0700 Subject: [PATCH] =?UTF-8?q?stt/tts=20label=20can=20be=20empty,=20should=20?= =?UTF-8?q?not=20assign=20application=20level=20label=E2=80=A6=20(#804)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * stt/tts label can be empty, should not assign application level label as default value * wip --- lib/tasks/config.js | 25 +++++++++++++------------ lib/tasks/say.js | 14 ++++++++------ lib/tasks/stt-task.js | 9 ++++++--- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/tasks/config.js b/lib/tasks/config.js index c85da18f..fbae6179 100644 --- a/lib/tasks/config.js +++ b/lib/tasks/config.js @@ -141,9 +141,8 @@ class TaskConfig extends Task { cs.speechSynthesisVendor = this.synthesizer.vendor !== 'default' ? this.synthesizer.vendor : cs.speechSynthesisVendor; - cs.speechSynthesisLabel = this.synthesizer.label !== 'default' - ? this.synthesizer.label - : cs.speechSynthesisLabel; + cs.speechSynthesisLabel = this.synthesizer.label === 'default' + ? cs.speechSynthesisLabel : this.synthesizer.label; cs.speechSynthesisLanguage = this.synthesizer.language !== 'default' ? this.synthesizer.language : cs.speechSynthesisLanguage; @@ -155,15 +154,16 @@ class TaskConfig extends Task { cs.fallbackSpeechSynthesisVendor = this.synthesizer.fallbackVendor !== 'default' ? this.synthesizer.fallbackVendor : cs.fallbackSpeechSynthesisVendor; - cs.fallbackSpeechSynthesisLabel = this.synthesizer.fallbackLabel !== 'default' - ? this.synthesizer.fallbackLabel - : cs.fallbackSpeechSynthesisLabel; + cs.fallbackSpeechSynthesisLabel = this.synthesizer.fallbackLabel === 'default' + ? cs.fallbackSpeechSynthesisLabel : this.synthesizer.fallbackLabel; cs.fallbackSpeechSynthesisLanguage = this.synthesizer.fallbackLanguage !== 'default' ? this.synthesizer.fallbackLanguage : cs.fallbackSpeechSynthesisLanguage; cs.fallbackSpeechSynthesisVoice = this.synthesizer.fallbackVoice !== 'default' ? this.synthesizer.fallbackVoice : cs.fallbackSpeechSynthesisVoice; + // new vendor is set, reset fallback vendor + cs.hasFallbackTts = false; this.logger.info({synthesizer: this.synthesizer}, 'Config: updated synthesizer'); } if (this.hasRecognizer) { @@ -171,9 +171,8 @@ class TaskConfig extends Task { cs.speechRecognizerVendor = this.recognizer.vendor !== 'default' ? this.recognizer.vendor : cs.speechRecognizerVendor; - cs.speechRecognizerLabel = this.recognizer.label !== 'default' - ? this.recognizer.label - : cs.speechRecognizerLabel; + cs.speechRecognizerLabel = this.recognizer.label === 'default' + ? cs.speechRecognizerLabel : this.recognizer.label; cs.speechRecognizerLanguage = this.recognizer.language !== 'default' ? this.recognizer.language : cs.speechRecognizerLanguage; @@ -182,9 +181,9 @@ class TaskConfig extends Task { cs.fallbackSpeechRecognizerVendor = this.recognizer.fallbackVendor !== 'default' ? this.recognizer.fallbackVendor : cs.fallbackSpeechRecognizerVendor; - cs.fallbackSpeechRecognizerLabel = this.recognizer.fallbackLabel !== 'default' - ? this.recognizer.fallbackLabel - : cs.fallbackSpeechRecognizerLabel; + cs.fallbackSpeechRecognizerLabel = this.recognizer.fallbackLabel === 'default' ? + cs.fallbackSpeechRecognizerLabel : + this.recognizer.fallbackLabel; cs.fallbackSpeechRecognizerLanguage = this.recognizer.fallbackLanguage !== 'default' ? this.recognizer.fallbackLanguage : cs.fallbackSpeechRecognizerLanguage; @@ -208,6 +207,8 @@ class TaskConfig extends Task { if ('punctuation' in this.recognizer) { cs.globalSttPunctuation = this.recognizer.punctuation; } + // new vendor is set, reset fallback vendor + cs.hasFallbackAsr = false; this.logger.info({ recognizer: this.recognizer, isContinuousAsr: cs.isContinuousAsr diff --git a/lib/tasks/say.js b/lib/tasks/say.js index b6c530cb..c0f1fb92 100644 --- a/lib/tasks/say.js +++ b/lib/tasks/say.js @@ -218,9 +218,10 @@ class TaskSay extends TtsTask { let voice = this.synthesizer.voice && this.synthesizer.voice !== 'default' ? this.synthesizer.voice : cs.speechSynthesisVoice; - let label = this.synthesizer.label && this.synthesizer.label !== 'default' ? - this.synthesizer.label : - cs.speechSynthesisLabel; + // label can be null/empty in synthesizer config, just use application level label if it's default + let label = this.synthesizer.label === 'default' ? + cs.speechSynthesisLabel : + this.synthesizer.label; const fallbackVendor = this.synthesizer.fallbackVendor && this.synthesizer.fallbackVendor !== 'default' ? this.synthesizer.fallbackVendor : @@ -231,9 +232,10 @@ class TaskSay extends TtsTask { const fallbackVoice = this.synthesizer.fallbackVoice && this.synthesizer.fallbackVoice !== 'default' ? this.synthesizer.fallbackVoice : cs.fallbackSpeechSynthesisVoice; - const fallbackLabel = this.synthesizer.fallbackLabel && this.synthesizer.fallbackLabel !== 'default' ? - this.synthesizer.fallbackLabel : - cs.fallbackSpeechSynthesisLabel; + // label can be null/empty in synthesizer config, just use application level label if it's default + const fallbackLabel = this.synthesizer.fallbackLabel === 'default' ? + cs.fallbackSpeechSynthesisLabel : + this.synthesizer.fallbackLabel; if (cs.hasFallbackTts) { vendor = fallbackVendor; diff --git a/lib/tasks/stt-task.js b/lib/tasks/stt-task.js index b233312d..6ad186fe 100644 --- a/lib/tasks/stt-task.js +++ b/lib/tasks/stt-task.js @@ -33,7 +33,8 @@ class SttTask extends Task { //fallback this.fallbackVendor = recognizer.fallbackVendor || 'default'; this.fallbackLanguage = recognizer.fallbackLanguage || 'default'; - this.fallbackLabel = recognizer.fallbackLabel || 'default'; + // label can be empty and should not have default value. + this.fallbackLabel = recognizer.fallbackLabel; /* let credentials be supplied in the recognizer object at runtime */ this.sttCredentials = setSpeechCredentialsAtRuntime(recognizer); @@ -81,7 +82,8 @@ class SttTask extends Task { this.language = cs.speechRecognizerLanguage; if (this.data.recognizer) this.data.recognizer.language = this.language; } - if ('default' === this.label || !this.label) { + // label can be empty, should not assign application level label + if ('default' === this.label) { this.label = cs.speechRecognizerLabel; if (this.data.recognizer) this.data.recognizer.label = this.label; } @@ -94,7 +96,8 @@ class SttTask extends Task { this.fallbackLanguage = cs.fallbackSpeechRecognizerLanguage; if (this.data.recognizer) this.data.recognizer.fallbackLanguage = this.fallbackLanguage; } - if ('default' === this.fallbackLabel || !this.fallbackLabel) { + // label can be empty, should not assign application level label + if ('default' === this.fallbackLabel) { this.fallbackLabel = cs.fallbackSpeechRecognizerLabel; if (this.data.recognizer) this.data.recognizer.fallbackLabel = this.fallbackLabel; }