赞
踩
function voicePrompt (text) {
new Audio('https://tts.baidu.com/text2audio?cuid=baike&lan=ZH&ctp=2&pdt=301&vol=9&rate=32&per=4&tex=' + text).play()
}
export {
voicePrompt
}
// 语音提醒
import { voicePrompt } from './utils/voice'
Vue.prototype.$voice = voicePrompt
this.$voice('您有新的订单,请及时处理')
<audio
controls
src="http://cdn.xxtao.com/cms/audio/yesterday once more.mp3">
</audio>
<div style="height:30px;line-height:30px;" class="flex_l"> <span>通话录音:</span> <audio id='audio' src='http://cdn.xxtao.com/cms/audio/yesterday once more.mp3' preload='metadata'> </audio> <i id="icon1" class="el-icon-video-play pointer size-20" onclick="play(1)"></i> <i id="icon2" style="display:none" class="el-icon-video-pause pointer size-20" onclick="play(2)"></i> </div> // 监听录音播放完毕 this.audio = document.querySelector('#audio'); this.audio.addEventListener('ended', e => { document.querySelector('#icon2').style.display = 'none' document.querySelector('#icon1').style.display = 'block' }); // 点击播放暂停录音 window.play = (e) => { if (e == 1) { document.querySelector('#icon1').style.display = 'none' document.querySelector('#icon2').style.display = 'block' this.audio.play() } else { document.querySelector('#icon2').style.display = 'none' document.querySelector('#icon1').style.display = 'block' this.audio.pause() } }
bug:用了几天MP3文件就失效了
<audio id="audio" src="https://www.coder.work/pub/text2audio/NAbPPbpW.mp3"></audio>
var Music = document.getElementById('audio')
Music.play()
var Music = new Audio('https://www.coder.work/pub/text2audio/NAbPPbpW.mp3')
Music.play()
new Audio("http://tts.youdao.com/fanyivoice?word=你好,我是你好&le=zh&keyfrom=speaker-target").play();
SpeechSynthesisUtterance是HTML5中新增的API,用于将指定文字合成为对应的语音.也包含一些配置项,指定如何去阅读(语言,音量,音调)等,不支持IE浏览器。
属性
方法
speak() 将对应的实例添加到语音队列中
cancel() 删除队列中所有的语音.如果正在播放,则直接停止
pause() 暂停语音
resume() 恢复暂停的语音
getVoices 获取支持的语言数组. 注意:必须添加在voiceschanged事件中才能生效
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。