js free text to speech code example

Example 1: how to do text to speech in javascript

var msg = new SpeechSynthesisUtterance();
msg.text = "Hello World";
window.speechSynthesis.speak(msg);

Example 2: js narrate text

// Narrate some text:
var msg = new SpeechSynthesisUtterance('Hello world!');
window.speechSynthesis.speak(msg);

// Cancel the narration:
window.speechSynthesis.cancel();

Example 3: speech to text in js

$('#pause-record-btn').on('click', function(e) {
  recognition.stop();
});