avRecorder如何录制wav格式的音频,默认MP3,能否直接改后缀?
// 开始录制对应的流程
async startRecordingProcess(): Promise<void> {
if (this.avRecorder !== undefined) {
await this.avRecorder.release();
this.avRecorder = undefined;
}
// 1.创建录制实例
this.avRecorder = await media.createAVRecorder();
this.setAudioRecorderCallback();
// 2.获取录制文件fd赋予avConfig里的url;参考FilePicker文档
const context = getContext(this);
const path = context.filesDir;
const filepath = path + '/01.mp3';
const file = fs.openSync(filepath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
const fdNumber = file.fd;
this.avConfig.url = 'fd://' + fdNumber;
// 3.配置录制参数完成准备工作
await this.avRecorder.prepare(this.avConfig);
// 4.开始录制
await this.avRecorder.start();
this.avRecorder!.getAudioCapturerMaxAmplitude((_: BusinessError, amplitude: number) => {
this.maxAmplitude = amplitude;
});
}, Const.COLUMN_HEIGHT);
}
使用WAV封装格式,参考AVRecorderProfile中的fileFormat 设置文件封装格式。需注意封装格式需设置对应支持的音频编码格式。参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-media-V5\#avrecorderprofile9