使用wx.getRecorderManager()获取全局唯一的录音管理器recorderManager,其recorderManager对象方法如下:
start(options)方法的参数说明如下:
采样率和码率关系如下:
audioSource的有效值如下:
onFrameRecorded(callback)回调结果如下:
录音管理的简单应用示例:
<!--wxml-->
<view class="title">第6章 媒体API</view>
<view class="demo-box">
<view class="title">录音管理器</view>
<button type="primary" size="mini" bindtap="start">开始录音</button>
<button type="primary" size="mini" bindtap="stop">停止录音</button>
</view>
//js
Page({
start:function(){
const options = {
duration:10000,
sampleRate:44100,
numberOfChannels:1,
encodeBitRate:192000,
format:'mp3',
frameSize:50
}
this.rm.start(options)
},
stop:function(options){
this.rm.stop()
},
onLoad:function(options){
this.rm = wx.getRecorderManager()
this.rm.onStop((res) => {
//播放录音内容
const audioCtx = wx.createInnerAudioContext()
audioCtx.src = res.tempFilePath
audioCtx.play()
})
}
})