Seb*_*i B 5 javascript text-to-speech
也许你们中的一些人也经历过同样的事情:
通过 Javascript使用语音合成时:
const utterance = new SpeechSynthesisUtterance(text);
utterance.addEventListener('start', () => {
console.log("Starting speak!");
});
window.speechSynthesis.speak(utterance);
Run Code Online (Sandbox Code Playgroud)
“开始说话”是在语音真正说话之前 1-4 秒触发的。它在 macOS 上的 safari 上运行良好,但在 Firefox 和 chrome 上都不起作用。
小智 1
有些声音可能有缺陷。
这会在 Mac 上的 FireFox 116.0.2 中产生延迟,并导致 CPU 使用率激增。
window.speechSynthesis.speak(Object.assign(new SpeechSynthesisUtterance('Hallo Bob'), {
voice: window.speechSynthesis.getVoices().find(v => v.lang === 'de-DE' && v.name == "Anna")
}))
Run Code Online (Sandbox Code Playgroud)