Search code examples
javascripthtmltext-to-speech

HTML5 Speech Synthesis


Simply put, it is very simple and contains minimum amount of conding (only two lines)

but I am still not hearing anything. But Google TTS works perfectly on my laptop.

I only see "one two" alert when I run the page below.

<!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>

And I use Google Chrome Ver 36. How do I view the errors in my JavaScript? Thanks a lot Stack Overflow!


Solution

  • I helped put speech synth in google chrome. Glad you are using it!

    **Edit: I ran your code in the Chrome 36 console and it works fine **

    You should be using it like so:

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

    You can check errors in the console in chrome by right clicking on the page and in the contextual menu, clicking the last option ( inspect element ).

    More here: https://developer.chrome.com/devtools/docs/console