平台差异说明

    recorderManager 对象的方法列表

    方法参数说明平台差异说明
    startoptions开始录音
    pause暂停录音
    resume继续录音
    stop停止录音
    onStartcallback录音开始事件
    onPausecallback录音暂停事件
    onStopcallback录音停止事件,会回调文件地址
    onFrameRecordedcallback已录制完指定帧大小的文件,会回调录音分片结果数据。如果设置了 frameSize ,则会回调此事件5+App 暂不支持
    onErrorcallback录音错误事件, 会回调错误信息

    其中,采样率和码率有一定要求,具体有效值如下:

    采样率编码码率
    800016000 ~ 48000
    1102516000 ~ 48000
    1200024000 ~ 64000
    1600024000 ~ 96000
    2205032000 ~ 128000
    2400032000 ~ 128000
    3200048000 ~ 192000
    4410064000 ~ 320000
    4800064000 ~ 320000

    onStop(callback) 回调结果说明

    属性类型说明
    frameBufferArrayBuffer录音分片结果数据
    isLastFrameBoolean当前帧是否正常录音结束前的最后一帧

    onError(callback) 回调结果说明

    示例

    1. const recorderManager = uni.getRecorderManager();
    2. const innerAudioContext = uni.createInnerAudioContext();
    3. innerAudioContext.autoplay = true;
    4. export default {
    5. data: {
    6. text: 'uni-app',
    7. voicePath: ''
    8. },
    9. onLoad() {
    10. recorderManager.onStop(function (res) {
    11. console.log('recorder stop' + JSON.stringify(res));
    12. self.voicePath = res.tempFilePath;
    13. });
    14. },
    15. methods: {
    16. startRecord() {
    17. console.log('开始录音');
    18. recorderManager.start();
    19. },
    20. console.log('录音结束');
    21. recorderManager.stop();
    22. },
    23. playVoice() {
    24. console.log('播放录音');
    25. if (this.voicePath) {
    26. innerAudioContext.src = this.voicePath;
    27. innerAudioContext.play();
    28. }
    29. }
    30. }