From 08ab494cef59c04ffbc28ca330711364edb02499 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Thu, 31 Aug 2023 08:07:03 +0700 Subject: [PATCH] feat azure fromhost (#302) * feat azure fromhost * wip * wip * wip * wip * fix review comment * fix review comment * wip * wip --- src/api/types.ts | 2 + .../internal/views/speech-services/form.tsx | 292 +++++++++++++----- src/utils/index.ts | 4 + 3 files changed, 220 insertions(+), 78 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index c6ec62e..77f228e 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -386,8 +386,10 @@ export interface SpeechCredential { secret_access_key: null | string; service_key: null | string; use_custom_tts: number; + custom_tts_endpoint_url: null | string; custom_tts_endpoint: null | string; use_custom_stt: number; + custom_stt_endpoint_url: null | string; custom_stt_endpoint: null | string; client_id: null | string; secret: null | string; diff --git a/src/containers/internal/views/speech-services/form.tsx b/src/containers/internal/views/speech-services/form.tsx index c0cd30f..fa5a927 100644 --- a/src/containers/internal/views/speech-services/form.tsx +++ b/src/containers/internal/views/speech-services/form.tsx @@ -36,6 +36,7 @@ import { checkSelectOptions, getObscuredSecret, isUserAccountScope, + isNotBlank, } from "src/utils"; import { getObscuredGoogleServiceKey } from "./utils"; import { CredentialStatus } from "./status"; @@ -76,10 +77,18 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { const [ttsRegion, setTtsRegion] = useState(""); const [ttsApiKey, setTtsApiKey] = useState(""); const [instanceId, setInstanceId] = useState(""); + const [initialCheckCustomTts, setInitialCheckCustomTts] = useState(false); + const [initialCheckCustomStt, setInitialCheckCustomStt] = useState(false); + const [initialCheckOnpremAzureService, setInitialCheckOnpremAzureService] = + useState(false); const [useCustomTts, setUseCustomTts] = useState(false); const [useCustomStt, setUseCustomStt] = useState(false); + const [customTtsEndpointUrl, setCustomTtsEndpointUrl] = useState(""); + const [tmpCustomTtsEndpointUrl, setTmpCustomTtsEndpointUrl] = useState(""); const [customTtsEndpoint, setCustomTtsEndpoint] = useState(""); const [tmpCustomTtsEndpoint, setTmpCustomTtsEndpoint] = useState(""); + const [customSttEndpointUrl, setCustomSttEndpointUrl] = useState(""); + const [tmpCustomSttEndpointUrl, setTmpCustomSttEndpointUrl] = useState(""); const [customSttEndpoint, setCustomSttEndpoint] = useState(""); const [tmpCustomSttEndpoint, setTmpCustomSttEndpoint] = useState(""); const [rivaServerUri, setRivaServerUri] = useState(""); @@ -150,9 +159,13 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { }), ...(vendor === VENDOR_MICROSOFT && { region: region || null, - use_custom_tts: useCustomTts ? 1 : 0, + use_custom_tts: + useCustomTts || isNotBlank(customTtsEndpointUrl) ? 1 : 0, + custom_tts_endpoint_url: customTtsEndpointUrl || null, custom_tts_endpoint: customTtsEndpoint || null, - use_custom_stt: useCustomStt ? 1 : 0, + use_custom_stt: + useCustomStt || isNotBlank(customSttEndpointUrl) ? 1 : 0, + custom_stt_endpoint_url: customSttEndpointUrl || null, custom_stt_endpoint: customSttEndpoint || null, }), ...(vendor === VENDOR_IBM && { @@ -208,13 +221,15 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { vendor === VENDOR_GOOGLE ? JSON.stringify(googleServiceKey) : null, access_key_id: vendor === VENDOR_AWS ? accessKeyId : null, secret_access_key: vendor === VENDOR_AWS ? secretAccessKey : null, - api_key: - vendor === VENDOR_MICROSOFT || - vendor === VENDOR_WELLSAID || - vendor === VENDOR_DEEPGRAM || - vendor === VENDOR_SONIOX - ? apiKey - : null, + ...(apiKey && { + api_key: + vendor === VENDOR_MICROSOFT || + vendor === VENDOR_WELLSAID || + vendor === VENDOR_DEEPGRAM || + vendor === VENDOR_SONIOX + ? apiKey + : null, + }), riva_server_uri: vendor == VENDOR_NVIDIA ? rivaServerUri : null, }) .then(() => { @@ -332,13 +347,26 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { if (credential.data.riva_server_uri) { setRivaServerUri(credential.data.riva_server_uri); } - setUseCustomTts(credential.data.use_custom_tts > 0 ? true : false); setUseCustomStt(credential.data.use_custom_stt > 0 ? true : false); + + setCustomTtsEndpointUrl(credential.data.custom_tts_endpoint_url || ""); + setCustomSttEndpointUrl(credential.data.custom_stt_endpoint_url || ""); + setTmpCustomTtsEndpointUrl(credential.data.custom_tts_endpoint_url || ""); + setTmpCustomSttEndpointUrl(credential.data.custom_stt_endpoint_url || ""); + setCustomTtsEndpoint(credential.data.custom_tts_endpoint || ""); setCustomSttEndpoint(credential.data.custom_stt_endpoint || ""); setTmpCustomTtsEndpoint(credential.data.custom_tts_endpoint || ""); setTmpCustomSttEndpoint(credential.data.custom_stt_endpoint || ""); + + setInitialCheckCustomTts(isNotBlank(credential.data.custom_tts_endpoint)); + setInitialCheckCustomStt(isNotBlank(credential.data.custom_stt_endpoint)); + setInitialCheckOnpremAzureService( + isNotBlank(credential.data.custom_tts_endpoint_url) || + isNotBlank(credential.data.custom_stt_endpoint_url) + ); + setCustomVendorName( credential.data.vendor.startsWith(VENDOR_CUSTOM) ? credential.data.vendor.substring(VENDOR_CUSTOM.length + 1) @@ -716,8 +744,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { /> )} - {(vendor === VENDOR_MICROSOFT || - vendor === VENDOR_WELLSAID || + {(vendor === VENDOR_WELLSAID || vendor === VENDOR_DEEPGRAM || vendor === VENDOR_SONIOX) && (