textVoice: function () {
let me = this;
if (me.soundEg == '') {
alert("请您先填写播放示例!");
return false;
}
//语音播报2 H5
var num = 0;
var va;
va = setInterval(function () {
if (num == 2) {
clearInterval(va);
return num = 0;
}
var msg = new SpeechSynthesisUtterance(me.soundEg);
msg.rate = 0.5;
msg.lang = 'zh-CN';
// msg.lang='en-US';
console.log(window.speechSynthesis.getVoices())
window.speechSynthesis.speak(msg);
num += 1;
}, 1000);
百度接口语音
/**
* 调用百度的语音播报
* #spd 选填 语速,取值0-9,默认为5中语速
#pit 选填 音调,取值0-9,默认为5中语调
#vol 选填 音量,取值0-15,默认为5中音量
#per 选填 发音人选择, 0为普通女声,1为普通男生,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女声
var url = "http://tsn.baidu.com/text2audio?lan=zh&ctp=1&cuid="+cuid+"&tok="+myToken+"&tex="+text+"&vol="+vol+"&per="+per+"&spd="+spd+"&pit=" + pit;
*/
textVoice: function () {
let me = this;
me.concatContentForVoid();
if (me.soundEg == '') {
alert("请您先填写播放示例!");
return;
}
//调用百度接口
var url = "http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + encodeURI(this.soundEg);
var n = new Audio(url);
n.src = url;
n.play();
},