From dc519bdef978b97b23729a2502bbfc07a26b3d74 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:17:25 +0700 Subject: [PATCH] fix remove speech label, cause application save wrong label (#384) * fix remove speech label, cause application save wrong label * fix microsoft custom_tts input --- .../internal/views/applications/form.tsx | 65 ++++++++++++++----- .../views/applications/speech-selection.tsx | 2 +- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/containers/internal/views/applications/form.tsx b/src/containers/internal/views/applications/form.tsx index d49bafc..2151909 100644 --- a/src/containers/internal/views/applications/form.tsx +++ b/src/containers/internal/views/applications/form.tsx @@ -386,6 +386,53 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => { } }, [accountSid]); + useEffect(() => { + let label: string; + // Synthesis Label + label = application?.data?.speech_synthesis_label || ""; + if (ttsLabelOptions && !ttsLabelOptions.find((l) => l.value === label)) { + label = ttsLabelOptions.length ? ttsLabelOptions[0].value : ""; + } + setSynthLabel(label); + + // fallback Synthesis Label + label = application?.data?.fallback_speech_synthesis_label || ""; + if ( + fallbackTtsLabelOptions && + !fallbackTtsLabelOptions.find((l) => l.value === label) + ) { + label = fallbackTtsLabelOptions.length + ? fallbackTtsLabelOptions[0].value + : ""; + } + setFallbackSpeechSynthsisLabel(label); + + // regconizer label + label = application?.data?.speech_recognizer_label || ""; + if (sttLabelOptions && !sttLabelOptions.find((l) => l.value === label)) { + label = sttLabelOptions.length ? sttLabelOptions[0].value : ""; + } + setRecogLabel(label); + + // fallback regconizer label + label = application?.data?.fallback_speech_recognizer_label || ""; + if ( + fallbackSttLabelOptions && + !fallbackSttLabelOptions.find((l) => l.value === label) + ) { + label = fallbackSttLabelOptions.length + ? fallbackSttLabelOptions[0].value + : ""; + } + setFallbackSpeechRecognizerLabel(label); + }, [ + ttsLabelOptions, + sttLabelOptions, + fallbackTtsLabelOptions, + fallbackSttLabelOptions, + application, + ]); + useEffect(() => { setLocation(); if (application && application.data) { @@ -462,12 +509,7 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => { if (application.data.speech_recognizer_language) setRecogLang(application.data.speech_recognizer_language); - if (application.data.speech_synthesis_label) { - setSynthLabel(application.data.speech_synthesis_label); - } - if (application.data.speech_recognizer_label) { - setRecogLabel(application.data.speech_recognizer_label); - } + if (application.data.use_for_fallback_speech) { setUseForFallbackSpeech(application.data.use_for_fallback_speech > 0); setInitalCheckFallbackSpeech( @@ -485,11 +527,7 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => { application.data.fallback_speech_recognizer_language ); } - if (application.data.fallback_speech_recognizer_label) { - setFallbackSpeechRecognizerLabel( - application.data.fallback_speech_recognizer_label - ); - } + if (application.data.fallback_speech_synthesis_vendor) { setFallbackSpeechSynthsisVendor( application.data @@ -506,11 +544,6 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => { application.data.fallback_speech_synthesis_voice ); } - if (application.data.fallback_speech_synthesis_label) { - setFallbackSpeechSynthsisLabel( - application.data.fallback_speech_synthesis_label - ); - } } }, [application]); diff --git a/src/containers/internal/views/applications/speech-selection.tsx b/src/containers/internal/views/applications/speech-selection.tsx index eb2ed6b..f86c44b 100644 --- a/src/containers/internal/views/applications/speech-selection.tsx +++ b/src/containers/internal/views/applications/speech-selection.tsx @@ -142,7 +142,7 @@ export const SpeechProviderSelection = ({ if (credentials) { setSelectedCredential( credentials.find( - (c) => c.vendor === synthVendor && c.label === synthLabel + (c) => c.vendor === synthVendor && (c.label || "") === synthLabel ) ); }