[JavaScript] Test Text-to-Speech in Web Speech API


Test Text-to-Speech (TTS) feature in Web Speech API. Not working in Chromium 57, but working in Firefox 53 (both running on Ubuntu Linux 17.04).

HTML:

<input type="text" value="hello world" id="text">
<button type="button" id="tts">Text to Speech</button>

JavaScript:

var input = document.querySelector("#text");
var tts = document.querySelector("#tts");

tts.addEventListener("click", function(e) {
  var text = new SpeechSynthesisUtterance(input.value);
  window.speechSynthesis.speak(text);
});

References:

[1]Using Google Text-To-Speech in Javascript - Stack Overflow
[2]Web apps that talk - Introduction to the Speech Synthesis API  |  Web  |  Google Developers
[3]javascript - Web speech api not working currently in chromium / electron / nw js? - Stack Overflow
[4]
[5]