HarmonyOS avRecorder如何录制wav格式的音频,默认MP3,能否直接改后缀?

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);
}
阅读 478
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进