vue-web端文字轉換為語音播報功能


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>  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM