Skip to content Skip to sidebar Skip to footer

Speechsynthesis Api Example Gives Error

The example given on Web Speech API Specification speechSynthesis.speak(SpeechSynthesisUtterance('Hello World')); gives the following error on chrome: Uncaught TypeError: D

Solution 1:

I think there is a type in the specifications and you are expected to use the new keyword with the SpeechSynthesisUtterance object. Try this:

speechSynthesis.speak(new SpeechSynthesisUtterance('Hello World'));

Solution 2:

Here's some code and a jsbin as well to help demonstrate how to use the APIs together:

var utterance = newwindow.SpeechSynthesisUtterance();
utterance.lang = 'ja-JP'; //translates on the fly - soooo awesome (japanese is the funniest)
utterance.volume = 1.0;
utterance.rate = 1.0;
utterance.pitch = 1.0;
utterance.voice = 'Hysterical'; // this seems to do nothing
utterance.text = "Facebook news feeds are full of garbage";

//Speak the phrasewindow.speechSynthesis.speak(utterance);

window.speechSynthesis.onvoiceschanged = function () {
  var speechSynthesisVoices = speechSynthesis.getVoices();
  var accents = _(speechSynthesisVoices).pluck('lang');
  var voices = _(speechSynthesisVoices).pluck('voiceURI');
  var names = _(speechSynthesisVoices).pluck('name');
  console.log('names', names);
  console.log('accents', _.uniq(accents));
  console.log('voices', voices);
};

Post a Comment for "Speechsynthesis Api Example Gives Error"