平台差异说明
recorderManager 对象的方法列表
方法 | 参数 | 说明 | 平台差异说明 |
---|---|---|---|
start | options | 开始录音 | |
pause | 暂停录音 | ||
resume | 继续录音 | ||
stop | 停止录音 | ||
onStart | callback | 录音开始事件 | |
onPause | callback | 录音暂停事件 | |
onStop | callback | 录音停止事件,会回调文件地址 | |
onFrameRecorded | callback | 已录制完指定帧大小的文件,会回调录音分片结果数据。如果设置了 frameSize ,则会回调此事件 | 5+App 暂不支持 |
onError | callback | 录音错误事件, 会回调错误信息 |
其中,采样率和码率有一定要求,具体有效值如下:
采样率 | 编码码率 |
---|---|
8000 | 16000 ~ 48000 |
11025 | 16000 ~ 48000 |
12000 | 24000 ~ 64000 |
16000 | 24000 ~ 96000 |
22050 | 32000 ~ 128000 |
24000 | 32000 ~ 128000 |
32000 | 48000 ~ 192000 |
44100 | 64000 ~ 320000 |
48000 | 64000 ~ 320000 |
onStop(callback) 回调结果说明
属性 | 类型 | 说明 |
---|---|---|
frameBuffer | ArrayBuffer | 录音分片结果数据 |
isLastFrame | Boolean | 当前帧是否正常录音结束前的最后一帧 |
onError(callback) 回调结果说明
示例
const recorderManager = uni.getRecorderManager();
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
export default {
data: {
text: 'uni-app',
voicePath: ''
},
onLoad() {
recorderManager.onStop(function (res) {
console.log('recorder stop' + JSON.stringify(res));
self.voicePath = res.tempFilePath;
});
},
methods: {
startRecord() {
console.log('开始录音');
recorderManager.start();
},
console.log('录音结束');
recorderManager.stop();
},
playVoice() {
console.log('播放录音');
if (this.voicePath) {
innerAudioContext.src = this.voicePath;
innerAudioContext.play();
}
}
}