voiceFileToText method

Future<String> voiceFileToText(
  1. String filePath, {
  2. ChatVoiceParam? voiceParam,
})

将语音文件转换为文字。

Param filePath 语音文件的本地路径。

Param voiceParam (可选)描述语音文件格式的参数,详见 ChatVoiceParam

Return 转换后的文本内容。

Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError

Implementation

Future<String> voiceFileToText(
  String filePath, {
  ChatVoiceParam? voiceParam,
}) async {
  try {
    Map req = {"filePath": filePath};
    req.putIfNotNull("voiceParam", voiceParam?.toJson());
    Map result = await platform_interface.Client.instance.chatManager
        .callNativeMethod(ChatMethodKeys.voiceFileToText, req);
    ChatError.hasErrorFromResult(result);
    return result[ChatMethodKeys.voiceFileToText]?["text"];
  } catch (e) {
    rethrow;
  }
}