vue项目中利用H5的语音合成实现语音播报

来源:so.csdn.net 发布时间:Dec 4, 2020, 10:51:01 AM 原地址:https://blog.csdn.net/Leon_940002463/article/details/110660799
  1. 首先定义一个文字转语音的js文件

    const synth = window.speechSynthesis
    
    /** * 文字转语音 * @author 袁首京 */
    export default {
         
    
      /** * 语音提醒 * @param {String} text */
      speek (text) {
         
        const ssu = new SpeechSynthesisUtterance(text)
        synth.speak(ssu)
      },
    
      /** * 退出语音 */
      cancel () {
         
        synth.cancel()
      }
    }
    
    
    1. 在需要的页面引入,并使用

      import tts from './utils/tts'
      
      tts.speek('卧槽!博主是个大帅逼!')