35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
|
|
function speakWithRegisteredEngine(){
|
||
|
|
const _opts={
|
||
|
|
voice: localStorage.getItem("hermes-tts-voice")||'',
|
||
|
|
rate: parseFloat(localStorage.getItem("hermes-tts-rate")),
|
||
|
|
};
|
||
|
|
return _opts;
|
||
|
|
}
|
||
|
|
function speakWithEdge(clean){
|
||
|
|
const voice=localStorage.getItem("hermes-tts-voice")||"zh-CN-XiaoxiaoNeural";
|
||
|
|
const rate='';
|
||
|
|
const pitch='';
|
||
|
|
return fetch('/api/tts', {
|
||
|
|
body: JSON.stringify({text: clean, voice, rate, pitch})
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function speakWithBrowser(clean){
|
||
|
|
const utter=new SpeechSynthesisUtterance(clean);
|
||
|
|
const savedVoice=localStorage.getItem('hermes-tts-voice');
|
||
|
|
const voices=speechSynthesis.getVoices();
|
||
|
|
if(savedVoice&&voices.length){
|
||
|
|
const match=voices.find(v=>v.name===savedVoice);
|
||
|
|
if(match) utter.voice=match;
|
||
|
|
}
|
||
|
|
return utter;
|
||
|
|
}
|
||
|
|
function _mirrorSpeechSettingsFromServer(s){
|
||
|
|
const defaults={
|
||
|
|
tts_voice:'',
|
||
|
|
};
|
||
|
|
[
|
||
|
|
['tts_voice','hermes-tts-voice'],
|
||
|
|
].forEach(([settingKey,storageKey])=>localStorage.setItem(storageKey,s[settingKey]));
|
||
|
|
return defaults;
|
||
|
|
}
|