Index: ssts-web/src/main/webapp/js/speaker.js =================================================================== diff -u -r25369 -r25502 --- ssts-web/src/main/webapp/js/speaker.js (.../speaker.js) (revision 25369) +++ ssts-web/src/main/webapp/js/speaker.js (.../speaker.js) (revision 25502) @@ -30,6 +30,7 @@ try{ if(this.enabled && !this.sapi){ this.sapi=new ActiveXObject("sapi.spvoice"); + //this.sapi.Rate = 3; } }catch(e){} } @@ -40,7 +41,7 @@ msg = msg +''; if(msg.length){ //第二个参数表示异步方式 ,https://msdn.microsoft.com/en-us/library/ms720892(v=VS.85).aspx - this.sapi.Speak(msg,1); + this.sapi.Speak(msg,0); } } } @@ -317,4 +318,105 @@ } } -var smartSpeaker = new SmartSpeaker(); \ No newline at end of file +var smartSpeaker = new SmartSpeaker(); + + +/** + * 下面2个方法读wav音频文件,不属于tts + */ +function playSound(ids,src){ + var $ids = ids; + if(typeof src != undefined && src < 10){ + $ids.attr("src","audio/"+src+".wav"); + } +} + +/*function playAudioAndTts(amount,audioId){ + if(amount > 20){ + speaker.speak(amount); + }else if(amount > 9 && amount < 20){ + debugger; + playSound(audioId,amount); + playSound(audioId,amount); + }else{ + playSound(audioId,amount); + } +} +*/ +var audioTwo; +var audioOne; +function playSoundMore(ids1,src1,ids2,src2){ + console.log("ids2",ids2); + var $ids1 = ids1; + var $ids2 = ids2; + if(typeof src1 != undefined && src1 < 10 || typeof src2 != undefined && src2 < 10){ + $ids1.attr("src","audio/"+src1+".wav"); + setTimeout(function(){ + $ids2.attr("src","audio/"+src2+".wav"); + }, 300); + + } +} + +function sleep(numberMillis) { + var now = new Date(); + var exitTime = now.getTime() + numberMillis; + while (true) { + now = new Date(); + if (now.getTime() > exitTime) + return true; + } +} + +var t_playAudio = null; +function playAudioAsync(audioId1,amount){ + amount = amount+''; + if(amount.length <= 1){ + playSound(audioId1,amount); + }else{ + var curAmount = amount.substr(0,1); + var nextAmount = amount.substr(1); + playSound(audioId1,curAmount); + t_playAudio = setTimeout(function(){ + playAudioAsync(audioId1,nextAmount); + },490); + } +} + +var audioArray = []; +function playAudioAndTts(amount,audioId1,audioId2){ + var audioIds = audioId2; + if(t_playAudio != null){ + clearTimeout(t_playAudio); + t_playAudio = null; + } + playAudioAsync(audioId1,amount); + +// if(amount > 9){ +// var amountArry = amount.toString().split(""); +// for(var i=0;i0){ +// (function (x) { +// setTimeout(function () { +// console.log(x) +// },0) +// })(i); +// setTimeout(function(){ +// playSound(audioId1,amountArry[i]); +// }, 300); +// }else{ +// playSound(audioId1,amountArry[i]); +// } +// playSound(audioId1,amountArry[i]); +// sleep(490); +// } +// // speaker.speak(amount); +// }else if(amount > 9 && amount < 20){ +// var amountArry = amount.toString().split(""); +// audioOne = amountArry[0]; +// audioTwo = amountArry[1]; +// playSoundMore(audioId1,audioOne,audioIds,audioTwo); +// }else{ +// playSound(audioId1,amount); +// } +}