speechSynthesis.speak(SpeechSynthesisUtterance('Hello World'));
在chrome上给出以下错误:
未捕获的TypeError:无法将DOM对象构造函数调用为 功能
有人可以帮忙吗?
谢谢!
答案 0 :(得分:1)
我认为规范中有一种类型,您应该将new
关键字与SpeechSynthesisUtterance
对象一起使用。试试这个:
speechSynthesis.speak(new SpeechSynthesisUtterance('Hello World'));
答案 1 :(得分:1)
以下是一些代码和a jsbin as well,以帮助演示如何一起使用API:
var utterance = new window.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 phrase
window.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);
};