From 42acb64952c98e07a0b10bbc9bee4fefb8a72a79 Mon Sep 17 00:00:00 2001 From: LiJun <LiJun@192.168.10.17> Date: 星期一, 29 十月 2018 16:42:33 +0800 Subject: [PATCH] 发声对象添加 --- gx_tieta/WebRoot/Test.jsp | 44 ++-------------------- gx_tieta/WebRoot/js/VoiceUtil.js | 44 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/gx_tieta/WebRoot/Test.jsp b/gx_tieta/WebRoot/Test.jsp index 639e23c..77b967f 100644 --- a/gx_tieta/WebRoot/Test.jsp +++ b/gx_tieta/WebRoot/Test.jsp @@ -20,10 +20,8 @@ <link rel="stylesheet" type="text/css" href="styles.css"> --> <link rel="stylesheet" type="text/css" href="css/basic.css" /> - <script type="text/javascript" src="js/frame.js"></script> <script type="text/javascript" src="js/jquery-1.8.3.js"></script> <script type="text/javascript" src="js/base.js"></script> - <script type="text/javascript" src="js/buildNav.js"></script> </head> <body> <!-- <form action="MyFileAction!UploadTestFile" method="post" enctype="multipart/form-data" id="up-form1"> @@ -38,7 +36,7 @@ <img alt="" id="im" src=""> </form> </body> - + <script type="text/javascript" src="js/VoiceUtil.js"></script> <script type="text/javascript"> var permits; <% Object obj=session.getAttribute("permits"); @@ -49,43 +47,9 @@ <% } %> - - - var param = { - dev_id:910000001, - record_datetime:'2018-01-01 00:00:00', - record_datetime_end:'2018-03-30 23:59:59', - station_event_type:0, //1:鍩虹珯鍋滅數 2:鍩虹珯缁埅 3:鍩虹珯鍙戠數 4:鍩虹珯寮�闂� 5:鍩虹珯鎺夌珯 6:鍩虹珯娓╁害涓婇檺 7:鍩虹珯娓╁害涓嬮檺 8:鍩虹珯婀垮害涓婇檺 9:鍩虹珯婀垮害涓嬮檺 - page:{ - pageSize:10, //姣忛〉鐨勮鏁� - pageCurr:1 //褰撳墠椤电爜鏁� - } - }; - searchStationHistRecord(param); - - //鏌ヨ鍩虹珯璇︽儏 - function searchStationHistRecord(param){ - // 璇锋眰鑾峰彇褰撳墠鐪佷笅鐨勫競 - $.ajax({ - type: "post", - url: "Bts_station_eventAction!serchByInfo", - async:true, - dataType:'json', - data:"json = "+JSON.stringify(param), - success: function(data){ - var rs = JSON.parse(data.result); - console.info(rs); - if(rs.code == 1) { - - }else { - - } - } - }); - } - - - + setTimeout(function() { + voice.play("杩欐槸鎴戠涓�娆″仛璇煶鎾姤鍦� 2018-01-01 01:56:23"); + },2000); //涓婁紶logo $('#up-file1').click(function(){ diff --git a/gx_tieta/WebRoot/js/VoiceUtil.js b/gx_tieta/WebRoot/js/VoiceUtil.js new file mode 100644 index 0000000..a69bf9c --- /dev/null +++ b/gx_tieta/WebRoot/js/VoiceUtil.js @@ -0,0 +1,44 @@ +// 璁剧疆璇煶鎾姤瀵硅薄 +var Voice = function() { + this.speak = window.speechSynthesis; + this.voice = ''; + this.zh_CN = false; + this._setLang(); // 鑾峰彇骞舵娴嬫槸鍚︽湁涓枃鐨勭幆澧� +}; + +// 鎾姤璇煶 (璋冪敤鍙戝0鐨勬柟娉曟椂璇蜂娇鐢ㄥ欢鏃跺彂澹�) +Voice.prototype.play = function(txt) { + if(!this.zh_CN) { + console.info('浣犵殑鐢佃剳涓嶆敮鎸佷腑鏂囨挱鎶ワ紒'); + } + console.info(this.zh_CN); + this.cancel(); + var to_speak = new SpeechSynthesisUtterance(txt); + to_speak.voice = this.voice; // 璁惧畾涓枃鎾姤 + + this.speak.speak(to_speak); + +}; + +// 閫�鍑哄綋鍓嶆挱鎶� +Voice.prototype.cancel = function() { + this.speak.cancel(); +}; + +// 妫�鏌ュ綋鍓嶈瑷�鐜 +Voice.prototype._setLang = function() { + var _this = this; + setTimeout(function(){ + var voices = _this.speak.getVoices(); + for(var i=0; i<voices.length; i++) { + var _voices = voices[0]; + //console.info(_voices); + if(_voices.lang === 'zh-CN') { + _this.zh_CN = true; + _this.voice = _voices; + } + } + }, 0); +}; + +var voice = new Voice(); -- Gitblit v1.9.1