介绍:
The SpeechSynthesisUtterance interface of the Web Speech API represents a speech request. It contains the content the speech service should read and information about how to read it (e.g. language, pitch and volume.).
也就是说SpeechSynthesisUtterance接口提供了语音服务,他可以阅读文本内容,以及配置语言,音量,音量。
让我们简单来实现以下。
示例
1 | <input placeholder="Type your text" type="text"> |
1 | const speak = () => { |
就这么简单,获取到文本内容,实例化SpeechSynthesisUtterance
,通过speechSynthesis
api将其添加到语音队列
即可。
兼容性
兼容大部分浏览器,不兼容Android
浏览器
天马行空
这项技术是否可以为无障碍和辅助技术
,自定义报警语音
,聊天机器人
ok,今天的学习分享就到这了。