janantala / speech-synthesis

Speech Synthesis polyfill
http://janantala.github.io/speech-synthesis/
MIT License
69 stars 21 forks source link

TypeError in Firefox 31 #13

Closed peterbe closed 10 years ago

peterbe commented 10 years ago

Using

var fallbackSpeechSynthesis = window.speechSynthesis || window.speechSynthesisPolyfill;
var fallbackSpeechSynthesisUtterance = window.SpeechSynthesisUtterance || window.SpeechSynthesisUtterancePolyfill;

function playWord(word, lang) {
    console.log(word, lang);
    var u = new fallbackSpeechSynthesisUtterance(word);
    lang = lang || 'en-US';
    u.lang = lang;
    u.volume = 1.0;
    u.rate = 1.0;
    // u.onend = function(event) { console.log('Finished in ' + event.elapsedTime + ' seconds.'); };
    fallbackSpeechSynthesis.speak(u);
}

I get:

TypeError: Argument 1 of SpeechSynthesis.speak does not implement interface SpeechSynthesisUtterance.

Strangely the example on http://janantala.github.io/speech-synthesis/ works in this browser.

peterbe commented 10 years ago

Ah! I see why, the demo doesn't attempt to use window.speechSynthesis or window.SpeechSynthesisUtterance

peterbe commented 10 years ago

If I change my app to only use the polyfill it works for me too. Not ideal though.

janantala commented 10 years ago

It looks like there is already a SpeechSynthesis object in Firefox (v28, in v26 it is ok) but no SpeechSynthesisUtterance.

SpeechSynthesis {pending: false, speaking: false, paused: false}

So we still can't use native speech synthesis and we will need a better detection. I will update docs.

janantala commented 10 years ago

Check out v0.4.0

var fallbackSpeechSynthesis = window.getSpeechSynthesis();
var fallbackSpeechSynthesisUtterance = window.getSpeechSynthesisUtterance();

var u = new fallbackSpeechSynthesisUtterance('Hello World');
u.lang = 'en-US';
u.volume = 1.0;
u.rate = 1.0;
u.onend = function(event) { console.log('Finished in ' + event.elapsedTime + ' seconds.'); };
fallbackSpeechSynthesis.speak(u);
peterbe commented 10 years ago

Works like a charm! Thank you!