You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo Go环境下React Native调用OpenAI语音转写接口报无效文件格式错误的解决求助

Expo Go环境下React Native调用OpenAI语音转写接口报无效文件格式错误的解决求助

各位大佬好!我现在用Expo Go开发React Native应用,需求很简单:点录制按钮开始录音,停止后把音频传给OpenAI转成文字,但卡壳了——OpenAI接口要的是File对象,可我只有音频的URI,结果调用时报了格式错误,头疼死了!

先贴报错信息:

ents/ExponentExperienceData/@levm38/ai-reminders/recording_1718887602296.mp3"
ERROR Failed to transcribe audio: [AxiosError: Request failed with status code 400]
LOG Response data: {"error": {"code": null, "message": "Invalid file format. Supported formats: ['flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga', 'oga', 'ogg', 'wav', 'webm']", "param": null, "type": "invalid_request_error"}}

我的停止录音相关代码是这样的:

const stopRecording = async () => {
  console.log('Stopping recording...');
  setRecording(null);
  setIsRecording(false);
  await recording?.stopAndUnloadAsync();

  const uri = recording?.getURI();
  if (uri) {
    // 这里是我尝试处理URI并调用OpenAI接口的逻辑,但完全没走通
    // 原代码没贴全,大概是直接用URI或者错误转了格式
  }
};

现在搞不懂两个点:

  1. 明明URI后缀是MP3,OpenAI却不认,难道Expo录的MP3在编码或者文件结构上和接口要求的不一样?
  2. 怎么把Expo录音得到的URI正确转成接口能接受的格式啊?毕竟接口不认URI,要的是File或者符合要求的请求体。

有没有走过同样坑的大佬给指条明路?感激不尽!

备注:内容来源于stack exchange,提问作者Luis Valencia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 12:13:10