LiJun
2018-10-30 f673b579d6af508ce76a8b671ec3e16ea8c0ee73
gx_tieta/WebRoot/js/VoiceUtil.js
@@ -1,11 +1,12 @@
// 设置语音播报对象
var Voice = function() {
   this.speak = window.speechSynthesis;
   this.tospeak = new SpeechSynthesisUtterance('');
   this.voice = '';
   this.zh_CN = false;
   this.rate = 1.5; 
   this._setLang();         // 获取并检测是否有中文的环境
   this.timeInterval = 28;      //循环间隔(秒)
   this.timeInterval = 27;      //循环间隔(秒)
   this.speak_enable = true;         //ture:开启语音播报         false:停止语音播报
};
@@ -25,14 +26,14 @@
      return;
   }
   this.cancel();
   var to_speak = new SpeechSynthesisUtterance(txt);
   to_speak.voice = this.voice;   // 设定中文播报
   to_speak.rate = this.rate;
   this.tospeak.text = txt;
   this.tospeak.voice = this.voice;   // 设定中文播报
   this.tospeak.rate = this.rate;
   //console.info(to_speak);
   var starttime = new Date();
   this.speak.speak(to_speak);
   console.info(to_speak);
   to_speak.onend = function(event) {
   this.speak.speak(this.tospeak);
   //console.info(this.tospeak);
   this.tospeak.onend = function(event) {
      //console.info("播放结束");
      if(callback && typeof callback == 'function'){
         var endtime = new Date();
@@ -48,9 +49,7 @@
      }
   };
   
   to_speak.onerror = function(event) {
      console.info(event);
   };
};
// 退出当前播报