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