xiangyuecn/Recorder

配置了type在停止录音时还是会报 -录音失败:未加载mp3编码器,请尝试到Recorder的src/engine内找到mp3的编码器并加载

Closed this issue · 3 comments

private initRecorder(): void {
this.recorderInstance = new Recorder({
sampleRate: 44100,
type:"mp3",
bitRate:16 ,
});
console.log('1', this.recorderInstance );

this.recorderInstance.open();
this.recorderInstance.onprocess = (e: any) => {
    // 默认处理逻辑
    console.log('e',e);
    
};

}
//打印出来的set也是显示设置好了的
set: {
bitRate: 16
onProcess: ƒ ()
sampleRate: 44100
type: "mp3"
}
//执行到 this.recorderInstance.stop回调时就会报未加载解码器了
// open start状态都是正常的
private async stopRecording(): Promise {
if (this.recorderInstance && this.isRecording) {

    this.recorderInstance.stop((blob:any,duration:any) => {
        console.log(blob,(window.URL||webkitURL).createObjectURL(blob),"时长:"+duration+"ms");
        
        
    },(msg:any)=>{
        console.log("录音失败:"+msg);
        this.recorderInstance.close();
        this.recorderInstance=null;
    });
    this.isRecording = false;
    this.isPaused = false;
    console.log('录音停止');
} else {
    Toast.fail('请先开始录音!');
}

}

啊,我也报这个错啊, 最后解决了么

import Recorder from "recorder-core";
import 'recorder-core/src/engine/wav.js'; // 你把wav.js切换为你对应的mp3.js

我的版本号是这个"recorder-core": "1.3.24040900",
QQ图片20240525165551

@LinForest-zZ 要按顺序import,需要什么格式就import什么格式的js,有些类型有-engine.js也一样的带上

import Recorder from "recorder-core";
import "recorder-core/src/engine/mp3.js";
import "recorder-core/src/engine/mp3-engine.js";