From f673b579d6af508ce76a8b671ec3e16ea8c0ee73 Mon Sep 17 00:00:00 2001 From: LiJun <LiJun@192.168.10.18> Date: 星期二, 30 十月 2018 11:10:05 +0800 Subject: [PATCH] 修复播报bug --- gx_tieta/WebRoot/js/VoiceUtil.js | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-) diff --git a/gx_tieta/WebRoot/js/VoiceUtil.js b/gx_tieta/WebRoot/js/VoiceUtil.js index d2b3d56..6bf489e 100644 --- a/gx_tieta/WebRoot/js/VoiceUtil.js +++ b/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); - }; + }; // 閫�鍑哄綋鍓嶆挱鎶� -- Gitblit v1.9.1