3

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

 2 years ago
source link: http://siongui.github.io/2017/04/22/javascript-test-tts-in-web-speech-api/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

April 22, 2017

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


Author: Siong-Ui Te Category: JavaScript

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK