From 1c02e66149af3199dad71e3fb93c36b3f7e871b9 Mon Sep 17 00:00:00 2001 From: LiJun <LiJun@192.168.10.18> Date: 星期二, 30 十月 2018 10:22:22 +0800 Subject: [PATCH] 告警语音播报 --- gx_tieta/WebRoot/Test.jsp | 4 - gx_tieta/WebRoot/js/VoiceUtil.js | 51 +++++++++++++++++++++++-- gx_tieta/WebRoot/Top.jsp | 39 +++++++++++++++++++ 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/gx_tieta/WebRoot/Test.jsp b/gx_tieta/WebRoot/Test.jsp index 77b967f..ffe00c7 100644 --- a/gx_tieta/WebRoot/Test.jsp +++ b/gx_tieta/WebRoot/Test.jsp @@ -47,9 +47,7 @@ <% } %> - setTimeout(function() { - voice.play("杩欐槸鎴戠涓�娆″仛璇煶鎾姤鍦� 2018-01-01 01:56:23"); - },2000); + //涓婁紶logo $('#up-file1').click(function(){ diff --git a/gx_tieta/WebRoot/Top.jsp b/gx_tieta/WebRoot/Top.jsp index fad10b8..b733db6 100644 --- a/gx_tieta/WebRoot/Top.jsp +++ b/gx_tieta/WebRoot/Top.jsp @@ -193,9 +193,12 @@ <script src="js/dev.js"></script> <script src="js/createTab.js"></script> <script type="text/javascript" src="js/scrollBar.js"></script> + <script type="text/javascript" src="js/VoiceUtil.js"></script> <script type="text/javascript"> $(document).ready(function(){ - setUserName(); + setUserName(); //璁剧疆鐢ㄦ埛鍚嶇О + + searchRecentlyAlarm(); //鏌ヨ鏈�杩�30绉掔殑璁惧鍜岀數姹犲憡璀� var lanuage=$('#top_cont .international .inter_action').attr('value'); $('#top_cont .international a').click(function() { @@ -328,6 +331,9 @@ } }); } + + + $(function(){ $.ajax({ @@ -681,6 +687,37 @@ }); } + + + //鏌ヨ鏈�杩�30鍐呯殑璁惧鍜岀數姹犲憡璀﹀苟鎾姤璇煶 + function searchRecentlyAlarm(){ + $.ajax({ + type: "post", + url: "Battalarm_dataAction!serchIn30", + async:true, + dataType:'json', + data:null, + success: function(data){ + console.info(data); + var model = eval("("+data.result+")"); + console.info(model); + if(model.code == 1){ + var alarm_str = ""; + for(var i=0;i<model.data.length;i++){ + var obj = model.data[i]; + alarm_str += obj.note+";"; + } + voice.play(alarm_str,searchRecentlyAlarm); + }else{ + setTimeout(searchRecentlyAlarm, 5000); + } + }, + error:function() { + setTimeout(searchRecentlyAlarm, 5000); + } + }); + } + // 鏍规嵁鏁版嵁鐢熸垚琛ㄦ牸 function createTblByModel(model) { //console.log(model); diff --git a/gx_tieta/WebRoot/js/VoiceUtil.js b/gx_tieta/WebRoot/js/VoiceUtil.js index a69bf9c..cfc0f6a 100644 --- a/gx_tieta/WebRoot/js/VoiceUtil.js +++ b/gx_tieta/WebRoot/js/VoiceUtil.js @@ -3,26 +3,66 @@ this.speak = window.speechSynthesis; this.voice = ''; this.zh_CN = false; - this._setLang(); // 鑾峰彇骞舵娴嬫槸鍚︽湁涓枃鐨勭幆澧� + this.rate = 1.5; + this._setLang(); // 鑾峰彇骞舵娴嬫槸鍚︽湁涓枃鐨勭幆澧� + this.timeInterval = 28; //寰幆闂撮殧(绉�) + this.speak_enable = true; //ture:寮�鍚闊虫挱鎶� false:鍋滄璇煶鎾姤 }; // 鎾姤璇煶 (璋冪敤鍙戝0鐨勬柟娉曟椂璇蜂娇鐢ㄥ欢鏃跺彂澹�) -Voice.prototype.play = function(txt) { +Voice.prototype.play = function(txt,callback) { if(!this.zh_CN) { console.info('浣犵殑鐢佃剳涓嶆敮鎸佷腑鏂囨挱鎶ワ紒'); } - console.info(this.zh_CN); + _timeInterval = this.timeInterval; + //console.info(this.zh_CN); + if(!this.speak_enable){ //璇嗗埆鏄惁寮�鍚0闊虫挱鎶� + if(callback && typeof callback == 'function'){ + setTimeout(function(){ + callback(); + }, Math.abs(_timeInterval)*1000); + } + return; + } this.cancel(); var to_speak = new SpeechSynthesisUtterance(txt); to_speak.voice = this.voice; // 璁惧畾涓枃鎾姤 - + to_speak.rate = this.rate; + console.info(to_speak); this.speak.speak(to_speak); + var starttime = new Date(); + to_speak.onend = function(event) { + //console.info(event); + if(callback && typeof callback == 'function'){ + var endtime = new Date(); + var timelong = (endtime.getTime()-starttime.getTime())/1000; + console.info(parseInt(_timeInterval)+"==="+parseInt(timelong)); + if(timelong > this.timeInterval){ + callback(); + }else{ + setTimeout(function(){ + callback(); + }, Math.abs(_timeInterval-timelong)*1000); + } + } + }; + + to_speak.onerror = function(event) { + //console.info(event); + }; }; // 閫�鍑哄綋鍓嶆挱鎶� Voice.prototype.cancel = function() { this.speak.cancel(); +}; + + +//鍋滄璇煶鎾姤 +Voice.prototype.stopSpeak = function() { + this.speak.cancel(); + this.speak_enable = false; }; // 妫�鏌ュ綋鍓嶈瑷�鐜 @@ -41,4 +81,7 @@ }, 0); }; + + var voice = new Voice(); +voice.cancel(); \ No newline at end of file -- Gitblit v1.9.1