diff --git a/api/server/services/Files/Audio/getCustomConfigSpeech.js b/api/server/services/Files/Audio/getCustomConfigSpeech.js index e9d185af2e..eca49f711b 100644 --- a/api/server/services/Files/Audio/getCustomConfigSpeech.js +++ b/api/server/services/Files/Audio/getCustomConfigSpeech.js @@ -26,6 +26,7 @@ async function getCustomConfigSpeech(req, res) { if (ttsSchema.advancedMode !== undefined) { settings.advancedMode = ttsSchema.advancedMode; } + if (ttsSchema.speechToText) { for (const key in ttsSchema.speechToText) { if (ttsSchema.speechToText[key] !== undefined) { @@ -33,6 +34,7 @@ async function getCustomConfigSpeech(req, res) { } } } + if (ttsSchema.textToSpeech) { for (const key in ttsSchema.textToSpeech) { if (ttsSchema.textToSpeech[key] !== undefined) { @@ -41,7 +43,7 @@ async function getCustomConfigSpeech(req, res) { } } - res.json(settings); + return res.status(200).send(settings); } catch (error) { res.status(200).send(); } diff --git a/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx b/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx index 48eafe86a9..df974db0e8 100644 --- a/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx +++ b/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx @@ -23,11 +23,11 @@ import { AutoSendTextSwitch, AutoTranscribeAudioSwitch, } from './STT'; -import { useCustomConfigSpeechQuery } from '~/data-provider'; +import { useGetCustomConfigSpeechQuery } from 'librechat-data-provider/react-query'; function Speech() { const [confirmClear, setConfirmClear] = useState(false); - const { data } = useCustomConfigSpeechQuery(); + const { data } = useGetCustomConfigSpeechQuery(); const isSmallScreen = useMediaQuery('(max-width: 767px)'); const [advancedMode, setAdvancedMode] = useRecoilState(store.advancedMode); @@ -66,10 +66,12 @@ function Speech() { playbackRate: { value: playbackRate, setFunc: setPlaybackRate }, }; - if (settings[key]) { - const setting = settings[key]; - setting.setFunc(newValue); + if (settings[key].value !== newValue || settings[key].value === newValue || !settings[key]) { + return; } + + const setting = settings[key]; + setting.setFunc(newValue); }, [ conversationMode, @@ -111,7 +113,8 @@ function Speech() { updateSetting(key, value); }); } - }, []); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [data]); const contentRef = useRef(null); useOnClickOutside(contentRef, () => confirmClear && setConfirmClear(false), []); diff --git a/packages/data-provider/src/data-service.ts b/packages/data-provider/src/data-service.ts index fadd438b49..f4e0d7018e 100644 --- a/packages/data-provider/src/data-service.ts +++ b/packages/data-provider/src/data-service.ts @@ -355,7 +355,7 @@ export const getVoices = (): Promise => { return request.get(endpoints.textToSpeechVoices()); }; -export const getCustomConfigSpeech = (): Promise => { +export const getCustomConfigSpeech = (): Promise => { return request.get(endpoints.getCustomConfigSpeech()); }; diff --git a/packages/data-provider/src/react-query/react-query-service.ts b/packages/data-provider/src/react-query/react-query-service.ts index 50632a3f1f..76f2c11c9f 100644 --- a/packages/data-provider/src/react-query/react-query-service.ts +++ b/packages/data-provider/src/react-query/react-query-service.ts @@ -422,3 +422,18 @@ export const useGetStartupConfig = ( }, ); }; + +export const useGetCustomConfigSpeechQuery = ( + config?: UseQueryOptions, +): QueryObserverResult => { + return useQuery( + [QueryKeys.customConfigSpeech], + () => dataService.getCustomConfigSpeech(), + { + refetchOnWindowFocus: false, + refetchOnReconnect: false, + refetchOnMount: false, + ...config, + }, + ); +}; diff --git a/packages/data-provider/src/types.ts b/packages/data-provider/src/types.ts index cfa9dfd55a..967e3de4a9 100644 --- a/packages/data-provider/src/types.ts +++ b/packages/data-provider/src/types.ts @@ -463,3 +463,5 @@ export type TGetRandomPromptsRequest = { limit: number; skip: number; }; + +export type TCustomConfigSpeechResponse = { [key: string]: string }; diff --git a/packages/data-provider/src/types/files.ts b/packages/data-provider/src/types/files.ts index 8650b39c28..8358549282 100644 --- a/packages/data-provider/src/types/files.ts +++ b/packages/data-provider/src/types/files.ts @@ -83,8 +83,6 @@ export type SpeechToTextResponse = { export type VoiceResponse = string[]; -export type getCustomConfigSpeechResponse = { [key: string]: string }; - export type UploadMutationOptions = { onSuccess?: (data: TFileUpload, variables: FormData, context?: unknown) => void; onMutate?: (variables: FormData) => void | Promise; @@ -115,12 +113,6 @@ export type VoiceOptions = { onError?: (error: unknown, variables: unknown, context?: unknown) => void; }; -export type getCustomConfigSpeechOptions = { - onSuccess?: (data: getCustomConfigSpeechResponse, variables: unknown, context?: unknown) => void; - onMutate?: () => void | Promise; - onError?: (error: unknown, variables: unknown, context?: unknown) => void; -}; - export type DeleteFilesResponse = { message: string; result: Record;