HTML5语音合成

Sno*_*now 3 javascript html5 text-to-speech

简单地说,它非常简单,包含最少的量(只有两行)

但我仍然没有听到任何声音.但谷歌TTS在我的笔记本电脑上完美运行.

当我运行下面的页面时,我只看到"一二"警报.

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head>

<body>

<script>
    var utterance = new SpeechSynthesisUtterance('Hello baby');
    window.speechSynthesis.speak(utterance);
    alert("one two");
</script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我使用Google Chrome版本36.如何在JavaScript中查看错误?非常感谢Stack Overflow!

wor*_*ith 8

我帮助将语音合成器放入谷歌浏览器中.很高兴你使用它!

**编辑:我在Chrome 36控制台中运行您的代码,它工作正常**

你应该像这样使用它:

if('speechSynthesis' in window){
    var speech = new SpeechSynthesisUtterance('hello baby');
    speech.lang = 'en-US';
    window.speechSynthesis.speak(speech);
}
Run Code Online (Sandbox Code Playgroud)

您可以通过右键单击页面并在上下文菜单中单击最后一个选项(检查元素)来检查控制台中的错误.

更多信息:https://developer.chrome.com/devtools/docs/console