const _SETTINGS_SPEECH_STORAGE_KEYS={ tts_engine:'hermes-tts-engine', tts_voice:'hermes-tts-voice', tts_rate:'hermes-tts-rate', }; let _settingsSpeechChangedKeys=new Set(); function _speechPreferencesPayloadFromUi(){ const payload={}; const ttsVoiceSel=$('settingsTtsVoice'); if(ttsVoiceSel) _setOwnedSpeechPayload(payload,'tts_voice',ttsVoiceSel.value||''); return payload; } function loadSettingsPanel(){ const ttsEngineSel=$('settingsTtsEngine'); if(ttsEngineSel){ ttsEngineSel.onchange=function(){ localStorage.setItem('hermes-tts-engine',this.value); window._populateTtsVoices(); _schedulePreferencesAutosave(); }; } // Populate voice selector based on engine const ttsVoiceSel=$('settingsTtsVoice'); window._populateTtsVoices=function(){ if(!ttsVoiceSel) return; const engine=localStorage.getItem('hermes-tts-engine')||'browser'; const current=String(_speechSetting('tts_voice','hermes-tts-voice','')||''); _syncSpeechPreferenceCache('tts_voice',current); if(engine==='edge'){ const edgeVoices=[ {value:'en-US-AriaNeural',label:'Aria (English, Female)'}, ]; ttsVoiceSel.innerHTML=''; edgeVoices.forEach(v=>ttsVoiceSel.appendChild(v)); } }; if(ttsVoiceSel&&'speechSynthesis' in window){ window._populateTtsVoices(); ttsVoiceSel.onchange=function(){_markSpeechPreferenceChanged('tts_voice');localStorage.setItem('hermes-tts-voice',this.value);_schedulePreferencesAutosave();}; } // TTS rate/pitch sliders }