语音合成API的例子给出了错误 [英] speechSynthesis API example gives error

查看:205
本文介绍了语音合成API的例子给出了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网络语音给出的例子API规范

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

给出了镀铬以下错误:

gives the following error on chrome:

未捕获类型错误:DOM对象的构造不能称之为一个
  功能。

Uncaught TypeError: DOM object constructor cannot be called as a function.

谁能帮助吗?

谢谢!

推荐答案

下面是一些code和的一jsbin以及,以帮助演示如何使用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的例子给出了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆