HarmonyOS 识别手机录制的语音失败?

step1: 用手机录制一段中文语音(调用avPlayer能如预期播放)

private avProfile: media.AVRecorderProfile = {
  audioBitrate: 100000, // 音频比特率
  audioChannels: 2, // 音频声道数
  audioCodec: media.CodecMimeType.AUDIO_AAC, // 音频编码格式,当前只支持aac
  audioSampleRate: 48000, // 音频采样率
  fileFormat: media.ContainerFormatType.CFT_MPEG_4A, // 封装格式,当前只支持m4a
};

参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/using-avrecorder-for-recording-V5

step2 用speechRecognizer读取并识别这段语音,却识别不到不效信息。

const audioRecorder = new AudioRecorderDemo();
await audioRecorder.startRecordingProcess(ctx);
await this.sleep(3000);
const audioFilePath = await audioRecorder.stopRecordingProcess();
let file = fileIo.openSync(audioFilePath, fileIo.OpenMode.READ_WRITE);
try {
  let buf: ArrayBuffer = new ArrayBuffer(1280);
  let offset: number = 0;
  while (1280 == fileIo.readSync(file.fd, buf, {
    offset: offset
  })) {
    let uint8Array: Uint8Array = new Uint8Array(buf);
    asrEngine.writeAudio("123456", uint8Array);
    await this.countDownLatch(1);
    offset = offset + 1280;
  }
}
speechRecognizer.RecognitionListener的onResult
{"isFinal":true,"isLast":true,"result":""}

参考 https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/speechrecognizer-guide-V5\#section56481271497

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