From 35fefed0792c40cb99b8d15fa5811bbb5992bff9 Mon Sep 17 00:00:00 2001
From: D:/workspace/chenjingjing/git/gx_tieta/gx_tieta/.gitignore <chenjingjing@LAPTOP-E51P2139>
Date: 星期一, 21 一月 2019 10:42:24 +0800
Subject: [PATCH] 修改

---
 gx_tieta/WebRoot/js/VoiceUtil.js |   94 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 87 insertions(+), 7 deletions(-)

diff --git a/gx_tieta/WebRoot/js/VoiceUtil.js b/gx_tieta/WebRoot/js/VoiceUtil.js
index a69bf9c..83f3db4 100644
--- a/gx_tieta/WebRoot/js/VoiceUtil.js
+++ b/gx_tieta/WebRoot/js/VoiceUtil.js
@@ -1,28 +1,77 @@
 // 璁剧疆璇煶鎾姤瀵硅薄
 var Voice = function() {
 	this.speak = window.speechSynthesis;
+	this.tospeak = new SpeechSynthesisUtterance('');
 	this.voice = '';
 	this.zh_CN = false;
-	this._setLang();	// 鑾峰彇骞舵娴嬫槸鍚︽湁涓枃鐨勭幆澧�
+	this.rate = 1.5; 
+	this._setLang();			// 鑾峰彇骞舵娴嬫槸鍚︽湁涓枃鐨勭幆澧�
+	this.timeInterval = 27;		//寰幆闂撮殧(绉�)
+	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.speak_enable);
+	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;	// 璁惧畾涓枃鎾姤
-
-	this.speak.speak(to_speak);
+	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(this.tospeak);
+	//console.info(this.tospeak);
+	this.tospeak.onend = function(event) {	
+		//console.info("鎾斁缁撴潫");
+		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);
+			}
+		}
+	};
 	
+
+};
+
+// 寮�鍚�/鍏抽棴褰撳墠璇煶鎾姤 锛堜緷璧栦笌base.js瀵煎叆鐨凜ookie鏂规硶锛�
+Voice.prototype.changeSpeak = function(bool) {
+	this.speak_enable = bool;
+	setCookie('voice', bool);
+	// 閫�鍑哄綋鍓嶆挱鎶�
+	if(!bool) {
+		this.cancel();
+	}
 };
 
 // 閫�鍑哄綋鍓嶆挱鎶�
 Voice.prototype.cancel = function() {
 	this.speak.cancel();
+};
+
+
+//鍋滄璇煶鎾姤
+Voice.prototype.stopSpeak = function() {
+	this.speak.cancel();
+	this.speak_enable = false;
 };
 
 // 妫�鏌ュ綋鍓嶈瑷�鐜
@@ -41,4 +90,35 @@
 	}, 0);
 };
 
+
+
 var voice = new Voice();
+var voiceStatus = checkPageVoiceStatus();
+// 璁剧疆鍒濆璇煶鎾姤鐘舵��
+voice.changeSpeak(voiceStatus);
+voice.cancel();
+
+// 璁剧疆鍒濆鍖栬闊虫挱鎶ュ浘鏍�
+if(!voiceStatus) {
+	$('.web-status .cell-list.voice').addClass('close-voice');
+}
+
+// 鐐瑰嚮澹伴煶鐨勫浘鏍�
+$('.web-status .cell-list.voice').click(function() {
+	$(this).toggleClass('close-voice');
+	// 鍒ゆ柇鏄惁鍏抽棴澹伴煶
+	if($(this).hasClass('close-voice')) {
+		voice.changeSpeak(false);
+	}else {
+		voice.changeSpeak(true);
+	}
+});
+
+// 鑾峰彇椤甸潰璇煶鏄惁寮�鍚�
+function checkPageVoiceStatus() {
+	var voiceStatus = getCookie('voice');
+	// 璁剧疆鍒濆璇煶鎾姤鐘舵��
+	voiceStatus = voiceStatus=='false'?false:true;
+	
+	return voiceStatus;
+}
\ No newline at end of file

--
Gitblit v1.9.1