🤖 refactor: Improve Speech Settings Initialization (#7869)

*  feat: Implement speech settings initialization and update settings handling

* 🔧 fix: Ensure setters reference is included in useEffect dependencies for speech settings initialization

* chore: Update setter reference in useSpeechSettingsInit for improved type safety

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Marco Beretta 2025-06-12 23:34:04 +02:00 committed by GitHub
parent 55f79bd2d1
commit 46ff008b07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 10 deletions

View file

@ -76,16 +76,10 @@ function Speech() {
playbackRate: { value: playbackRate, setFunc: setPlaybackRate },
};
if (
(settings[key].value !== newValue || settings[key].value === newValue || !settings[key]) &&
settings[key].value === 'sttExternal' &&
settings[key].value === 'ttsExternal'
) {
return;
}
const setting = settings[key];
setting.setFunc(newValue);
if (setting) {
setting.setFunc(newValue);
}
},
[
sttExternal,
@ -130,13 +124,20 @@ function Speech() {
useEffect(() => {
if (data && data.message !== 'not_found') {
Object.entries(data).forEach(([key, value]) => {
updateSetting(key, value);
// Only apply config values as defaults if no user preference exists in localStorage
const existingValue = localStorage.getItem(key);
if (existingValue === null && key !== 'sttExternal' && key !== 'ttsExternal') {
updateSetting(key, value);
} else if (key === 'sttExternal' || key === 'ttsExternal') {
updateSetting(key, value);
}
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data]);
// Reset engineTTS if it is set to a removed/invalid value (e.g., 'edge')
// TODO: remove this once the 'edge' engine is fully deprecated
useEffect(() => {
const validEngines = ['browser', 'external'];
if (!validEngines.includes(engineTTS)) {