gx_tieta/WebRoot/Test.jsp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
gx_tieta/WebRoot/Top.jsp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
gx_tieta/WebRoot/js/VoiceUtil.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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(){ 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); 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:停止语音播报 }; // 播报语音 (调用发声的方法时请使用延时发声) 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){ //识别是否开启声音播报 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();