百度合成
<audio ref="refAudio" :src="audioUrl">您的浏览器不支持 audio 标签。</audio>
handleSpeak(str){
if(this.audio != null){
this.audio.pause()
this.audio = null
}
this.$nextTick(() => {
this.audio = this.$refs.refAudio
let url="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=5&text="+encodeURI(str)
// this.audio = new Audio(url)
this.audio.src = url
this.audio.loop = false;
this.audio.play()
this.audio.addEventListener('ended', () => {
this.audio.pause()
this.audio = null
this.$nextTick(() => {
let text = ''
this.platformData.forEach(item => {
text +=`${item.truckNo}——请停靠——${item.name}——`
text +=`${item.truckNo}——请停靠——${item.name}——`
})
this.handleSpeak(text)
})
// $('#playvoice').attr("src",'images/play_voice_off.png');
}, false);
})
}
注意:new Audio 形式在关闭页面,再次打开该页面,audio 没被销毁,会多个声音触发。
html5 SpeechSynthesisUtterance
this.speechObj = new window.SpeechSynthesisUtterance();
this.speechObj.text = `【${this.platformData[idx].truckNo}】请停靠【${this.platformData[idx].name}】`
this.speechObj.volume = 1.5 // 播放音量
window.speechSynthesis.speak(this.speechObj);
win10环境下ie 没什么,win7系统所有浏览器都没声音(未解)。