1. 使用 Web Speech API :

     https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Speech_API

    能够将语音数据合并到 Web 应用程序中。 Web Speech API 有两个部分:SpeechSynthesis 语音合成 (文本到语音 TTS)和 SpeechRecognition  语音识别(异步语音识别)。

2. 使用案例:

<script>
  const synth = window.speechSynthesis;
  const msg = new SpeechSynthesisUtterance();
  export default {
       data() {
          return {};
       },
       mounted() {
          this.handleSpeak('你好哇');
       }
       methods: {
          // 语音播报
          handleSpeak(text) {
            console.log(text);
            this.msg.text = text;     // 文字内容
            this.msg.lang = "zh-CN";  // 使用的语言:中文
            this.msg.volume = 1;      // 声音音量:1
            this.msg.rate = 1;        // 语速:1
            this.msg.pitch = 1;       // 音高:1
            this.synth.speak(this.msg);    // 播放
          }
       }
     
  }
</script>  

 

posted on 2021-01-14 16:50  zoey-blog  阅读(1725)  评论(0编辑  收藏  举报