录音失败:未加载audio/wav编码器
Domineer-Long opened this issue · 1 comments
Domineer-Long commented
使用vue3 + recorder录制 wav 一直报错“录音失败:未加载audio/wav编码器,请尝试到Recorder的src/engine内找到audio/wav的编码器并加载”
使用的recorder依赖版本:
"recorder-core": "^1.3.24040900",
代码如下,还缺少什么吗?
import SpeechService from '../SpeechService';
import Recorder from 'recorder-core'
import 'recorder-core/src/engine/wav'
class RecorderService implements SpeechService{
audioConfig = {
sampleRate: 16000, // Azure支持的采样率
bitsPerSecond: 256, // Kbps 比特率
mimeType: 'audio/wav' // 目标格式
};
stopFn? : Function
rec:any
constructor(){
Recorder.ConnectEnableWebM=false
}
record(): void {
this.rec=Recorder({ //本配置参数请参考下面的文档,有详细介绍
type: this.audioConfig.mimeType,
sampleRate: this.audioConfig.sampleRate,
bitRate: this.audioConfig.bitsPerSecond //mp3格式,指定采样率hz、比特率kbps,其他参数使用默认配置;注意:是数字的参数必须提供数字,不要用字符串;需要使用的type类型,需提前把格式支持文件加载进来,比如使用wav格式需要提前加载wav.js编码引擎
});
this.rec.ConnectEnableWebM=false
const that = this
this.rec.open(function(){//打开麦克风授权获得相关资源
that.rec.start()
},function(msg:string,isUserNotAllow:boolean){//用户拒绝未授权或不支持
console.log((isUserNotAllow?"UserNotAllow,":"")+"无法录音:"+msg);
});
}
stop(): void {
let that=this
this.rec.stop(function(blob:Blob,duration:number){
console.log('rec stop execute stopFn')
that.stopFn&&that.stopFn(blob)
that.rec.close();//释放录音资源,当然可以不释放,后面可以连续调用start;但不释放时系统或浏览器会一直提示在录音,最佳操作是录完就close掉
that.rec=null;
},function(msg:string){
console.log("录音失败:"+msg);
that.rec.close();//可以通过stop方法的第3个参数来自动调用close
that.rec=null;
});
}
onstop(fn: Function): void {
this.stopFn = fn
}
}
Domineer-Long commented
已解决
mimeType: 'audio/wav' // 目标格式
这里应该为 wav
之前使用MediaRecorder
习惯性的写成 audio/wav