html 文字输出语音,html 录音与文本转语音demo
$(function(){
mui.init()
var rec=Recorder();//使用默認配置,mp3格式
$("#but").click(function(){
console.log("1");
var ssu = new window.SpeechSynthesisUtterance('蓬頭稚子學垂綸,側坐莓苔草映身。路人借問遙招手,怕得魚驚不應人。');
window.speechSynthesis.speak(ssu);
});
$("#start").click(function(){
alert("開始錄音")
rec.open(function(){//打開麥克風授權獲得相關資源
rec.start();//開始錄音
},function(msg,isUserNotAllow){//用戶拒絕未授權或不支持
console.log((isUserNotAllow?"UserNotAllow,":"")+"無法錄音:"+msg);
});
});
$("#end").click(function(){
alert("結束錄音");
rec.stop(function(blob,duration){//到達指定條件停止錄音
console.log(URL.createObjectURL(blob),"時長:"+duration+"ms");
rec.close();//釋放錄音資源
//已經拿到blob文件對象想干嘛就干嘛:立即播放、上傳
/*立即播放例子*/
var audio=document.createElement("audio");
audio.controls=true;
$("#audo").html(audio);
//document.body.appendChild(audio);
//簡單的一嗶
audio.src=URL.createObjectURL(blob);
audio.play();
},function(msg){
console.log("錄音失敗:"+msg);
});
})
})
播放
開始錄音
結束錄音
總結
以上是生活随笔為你收集整理的html 文字输出语音,html 录音与文本转语音demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 锁屏音量,Android
- 下一篇: 麒麟9905g版会用鸿蒙系统吗视频,几乎