微信小程序開發(fā)中,麥克風(fēng)錄音和音頻上傳非常常見。下面將詳細(xì)介紹如何使用微信小程序開發(fā)工具進(jìn)行麥克風(fēng)錄音和音頻上傳。
一、麥克風(fēng)錄音
首先在wxml文件中添加一個(gè)錄音按鈕,用于觸發(fā)錄音操作:
<button type="primary" bindtap="startRecord">開始錄音</button>
?文章來源:http://www.zghlxwxcb.cn/news/detail-760415.html
然后在js文件中定義startRecord事件,用于開始錄音:文章來源地址http://www.zghlxwxcb.cn/news/detail-760415.html
data:{
isRecord:false,
filePath:'',
recordingTime:0
},
startRecord:function(){
this.setData({
isRecord:true
})
const recorderManager = wx.getRecorderManager()
recorderManager.onStart(() => {
console.log('recorder start')
})
recorderManager.onError((res) => {
console.log(res)
})
recorderManager.onStop((res) => {
console.log('recorder stop', res)
this.setData({
filePath: res.tempFilePath
})
})
const options = {
duration: 60000, //最長錄音時(shí)長為1分鐘
sampleRate: 44100,
numberOfChann
到了這里,關(guān)于微信小程序開發(fā)中的麥克風(fēng)錄音和音頻上傳的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!