speechSynthesis API示例给出了错误
speechSynthesis API example gives error
关于Web语音API规范的示例
speechSynthesis.speak(SpeechSynthesisUtterance('Hello World'));
在chrome上给出以下错误:
Uncaught TypeError:DOM对象构造函数不能作为作用
这里有人能帮忙吗?
谢谢!
我认为规范中有一个类型,您应该将new
关键字与SpeechSynthesisUtterance
对象一起使用。试试这个:
speechSynthesis.speak(new SpeechSynthesisUtterance('Hello World'));
这里有一些代码和一个jsbin来帮助演示如何一起使用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);
};
相关文章:
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- 使用Yelp API时出现OAuth错误
- internet explorer 8兼容模式下的Youtube api错误
- 使用FB.ui的Facebook Feed对话给出API错误191
- DreamFactory REST API POST休息/用户/会话请求总是在IE9中返回错误
- 我该如何解决“;未捕获引用错误:谷歌没有定义"?(谷歌地图API)
- "未捕获的语法错误:意外的标记<"当尝试使用谷歌'核心报告API
- json-api和错误结果:无法读取属性'长度'的未定义
- 向Yahoo Finance API发出JSONP请求时获得400错误请求
- 使用javascript API响应内部服务器错误将曲目上传到SoundCloud
- 使用Google Analytics API的区域图-未采集类型错误无法读取'库'的未定义
- 使用gmail-api发送电子邮件错误:此api不支持解析表单编码的输入
- AWS API网关返回400错误请求,但Postman工作正常
- Javascript:可驱动api出现禁止的错误
- YouTube API v3哈希标签搜索错误结果
- 使用Twitter API进行推文时出现重复状态错误
- 岗位http://localhost:3000/api/signup400(错误请求)
- Google嵌入API cb=gap对象错误
- 科尔多瓦指南针 API 给出错误代码 3
- 在 api 调用$resource显示错误和成功消息