天润 PC 客户端语音播报

   
image.png

 image.png

// 语音播报的函数

      handleSpeak(text) {

          if (window.speechSynthesis) {

              const synth = window.speechSynthesis;

              const msg = new SpeechSynthesisUtterance();

              msg.text = text;// 文字内容

              msg.lang = “zh-CN”;// 使用的语言: 中文

              msg.volume = 1;// 声音音量:1

              msg.rate = 1;// 语速:5

              msg.pitch = 1;// 音高:1

              msg.voice = this.getWindowVoice()// 使用本地服务合成语音 ( 若是获取不到 请异步获取, 加一个 setTimeout)

              synth.speak(msg);// 播放

          }

      },
// 语音停止
      handleStop(e) {

          if (window.speechSynthesis) {

              const synth = window.speechSynthesis;

              const msg = new SpeechSynthesisUtterance();

              msg.text = e;

              msg.lang = “zh-CN”;

              synth.cancel(msg);

          }

      },