语音合成api_语音合成API

语音合成api

The Speech Synthesis API is an awesome tool provided by modern browsers.

语音合成API是现代浏览器提供的强大工具。

Introduced in 2014, it’s now widely adopted and available in Chrome, Firefox, Safari and Edge. IE is not supported.

它于2014年推出,现已 Chrome,Firefox,Safari和Edge 广泛采用并可用。 不支持IE。

Browser support for the Speech Synthesis API

It’s part of the Web Speech API, along with the Speech Recognition API, although that is only currently supported, in experimental mode, on Chrome.

它是Web Speech API的一部分,与Speech Recognition API一起 ,虽然目前仅在Chrome上以实验模式受支持。

I used it recently to provide an alert on a page that monitored some parameters. When one of the numbers went up, I was alerted thought the computer speakers.

我最近使用它在监视某些参数的页面上提供了警报。 当其中一个数字上升时,我就被计算机扬声器吓到了。

入门 (Getting started)

The most simple example of using the Speech Synthesis API stays on one line:

使用语音合成API的最简单示例停留在一行上:

speechSynthesis.speak(new SpeechSynthesisUtterance('Hey'))

Copy and paste it in your browser console, and your computer should speak!

将其复制并粘贴到您的浏览器控制台中,您的计算机就会讲话!

API (The API)

The API exposes several objects to the window object.

该API将多个对象公开给window对象。

SpeechSynthesisUtterance (SpeechSynthesisUtterance)

SpeechSynthesisUtterance represents a speech request. In the example above we passed it a string. That’s the message the browser should read aloud.

SpeechSynthesisUtterance表示语音请求。 在上面的示例中,我们为它传递了一个字符串。 那是浏览器应大声读出的消息。

Once you got the utterance object, you can perform some tweaks to edit the speech properties:

获得语音对象后,您可以进行一些调整以编辑语音属性:

const utterance = new SpeechSynthesisUtterance('Hey')
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值