作家
登录

网页中文本朗读功能开发实现分享

作者: 来源: 2017-12-11 16:19:20 阅读 我要评论


  • 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

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)