rate
: 语速 Gets and sets the speed at which the utterance will be spoken at.
text
: 文本 Gets and sets the text that will be synthesised when the utterance is spoken.
voice
: 声音 Gets and sets the voice that will be used to speak the utterance.
volume
: 音量 Gets and sets the volume that the utterance will be spoken at.
onboundary
: 单词或句子界线触发,即分隔处触发 Fired when the spoken utterance reaches a word or sentence boundary.
好了,筹划终于有了,并且这个筹划逻辑多简单,代码逻辑天然也不会烦。
onend
: 停止时触发 Fired when the utterance has finished being spoken.
onerror
: 缺点时触发 Fired when an error occurs that prevents the utterance from being succesfully spoken.
如许就可以获取到一个标签的功能提示和内容的全部带朗读文本了。
onmark
: Fired when the spoken utterance reaches a named SSML "mark" tag.
onpause
: 暂停时触发 Fired when the utterance is paused part way through.
onresume
: 从新播放时触发 Fired when a paused utterance is resumed.
onstart
: 开端时触发 Fired when the utterance has begun to be spoken.
SpeechSynthesis
: 用于朗读
-
paused
: Read>- var speaker = new window.SpeechSynthesisUtterance();
- var speakTimer,
- stopTimer;
- // 开妒攀朗读
- function speakText(text) {
- clearTimeout(speakTimer);
- window.speechSynthesis.cancel();
- speakTimer = setTimeout(function () {
- speaker.text = text;
- window.speechSynthesis.speak(speaker);
- }, 200);
- }
- // 停止朗读
- function stopSpeak() {
- clearTimeout(stopTimer);
- clearTimeout(speakTimer);
- stopTimer = setTimeout(function () {
- window.speechSynthesis.cancel();
- }, 20);
- }
现代浏览器已经内置了这个功能,两个API接口兼容性如下:
Feature
Chrome
Edge
Firefox (Gecko)
Internet Explorer
Opera
Safari
(WebKit) Basic
support 33
(Yes)
49 (49)
文本节点则分隔直接担保,标签节点则对内容进行担保,这种情况下处理的直接是dom,更省事。
No support
?
7
如不雅要兼容其他浏览器或者须要一种完良图容的解决筹划,可能就须要办事端完成了,根据给定文本,返回响应语音即可,百度语音 http://yuyin.baidu.com/docs就供给如许的办事。
-
想不明白问题二的,可参考一下待分隔的段落:
cdswyda - 网也文本朗读实现 - github
-
cdswyda - 网也文本朗读实现 - demo
推荐阅读
开辟者大年夜赛路演 | 12月16日,技巧立异,北京不见不散 硬件挖的坑真的可以经由过程软件来填吗?实际上不少硬>>>详细阅读
本文标题:网页中文本朗读功能开发实现分享
地址:http://www.17bianji.com/lsqh/39663.html
1/2 1