SpeechSynthesis API 示例给出错误 [英] speechSynthesis API example gives error

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

问题描述

网络演讲中给出的示例API 规范

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

在 chrome 上出现以下错误:

gives the following error on chrome:

未捕获的类型错误:DOM 对象构造函数不能作为功能.

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

有人可以帮忙吗?

谢谢!

推荐答案

我认为规范中有一个类型,你应该在 SpeechSynthesisUtterance 中使用 new 关键字代码>对象.试试这个:

I think there is a type in the specifications and you are expected to use the new keyword with the SpeechSynthesisUtterance object. Try this:

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

这篇关于SpeechSynthesis API 示例给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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