| | |
| | | // 设置语音播报对象
|
| | | 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:停止语音播报
|
| | | };
|
| | |
|
| | |
| | | console.info('你的电脑不支持中文播报!');
|
| | | }
|
| | | _timeInterval = this.timeInterval;
|
| | | //console.info(this.zh_CN);
|
| | | //console.info(this.speak_enable);
|
| | | if(!this.speak_enable){ //识别是否开启声音播报
|
| | | if(callback && typeof callback == 'function'){
|
| | | setTimeout(function(){
|
| | |
| | | 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);
|
| | | |
| | | this.tospeak.text = txt;
|
| | | this.tospeak.voice = this.voice; // 设定中文播报
|
| | | this.tospeak.rate = this.rate;
|
| | | //console.info(to_speak);
|
| | | var starttime = new Date();
|
| | | to_speak.onend = function(event) { |
| | | //console.info(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();
|
| | | var timelong = (endtime.getTime()-starttime.getTime())/1000;
|
| | | console.info(parseInt(_timeInterval)+"==="+parseInt(timelong));
|
| | | //console.info(parseInt(_timeInterval)+"==="+parseInt(timelong));
|
| | | if(timelong > this.timeInterval){
|
| | | callback();
|
| | | }else{
|
| | |
| | | }
|
| | | };
|
| | |
|
| | | to_speak.onerror = function(event) { |
| | | //console.info(event);
|
| | | };
|
| | |
|
| | | };
|
| | |
|
| | | // 开启/关闭当前语音播报 (依赖与base.js导入的Cookie方法)
|
| | | Voice.prototype.changeSpeak = function(bool) {
|
| | | this.speak_enable = bool;
|
| | | setCookie('voice', bool);
|
| | | // 退出当前播报
|
| | | if(!bool) {
|
| | | this.cancel();
|
| | | }
|
| | | };
|
| | |
|
| | | // 退出当前播报
|
| | |
| | |
|
| | |
|
| | | var voice = new Voice();
|
| | | voice.cancel(); |
| | | 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;
|
| | | } |