本文介绍了语音合成API的例子给出了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在
speechSynthesis.speak(SpeechSynthesisUtterance('Hello World'));
给出了镀铬以下错误:
gives the following error on chrome:
未捕获类型错误:DOM对象的构造不能称之为一个
功能。
谁能帮助吗?
谢谢!
推荐答案
下面是一些code和的,以帮助演示如何使用API一起使用:
Here's some code and a jsbin as well to help demonstrate how to use the APIs together:
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);
};
这篇关于语音合成API的例子给出了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!