Hi OpenAI team,
I’m running into a Network Error (ERR_NETWORK) when trying to call the /v1/audio/transcriptions endpoint using the Whisper API. This happens when uploading a local audio file recorded on a mobile device (React Native).
Also other errors that get randomness in my log system:
"message": "Request failed with status code 400",
OR
"_response": "bad URL",
OR
"message": "Network Error",
Here’s the full error response from the API:
{
"code": "ERR_NETWORK",
"config": {
"adapter": [
"xhr",
"http",
"fetch"
],
"data": {
"_parts": [
[
"file",
{
"name": "sound.m4a",
"type": "audio/m4a",
"uri": "file:///var/mobile/Containers/Data/Application/33670439-1E2B-4650-9D08-2B5890F9/Library/Caches/sound.m4a"
}
],
[
"model",
"whisper-1"
]
]
},
"env": {
"Blob": "<null>",
"FormData": "<null>"
},
"headers": {
"Accept": "application/json, text/plain, */*",
"Authorization": "Bearer sk-....",
"Content-Type": "multipart/form-data"
},
"maxBodyLength": -1,
"maxContentLength": -1,
"method": "post",
"timeout": 50000,
"transformRequest": [],
"transformResponse": [],
"transitional": {
"clarifyTimeoutError": false,
"forcedJSONParsing": true,
"silentJSONParsing": true
},
"url": "https://api.openai.com/v1/audio/transcriptions",
"validateStatus": "<null>",
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN"
},
"constructor": "<null>",
"message": "Network Error",
"name": "AxiosError"
}
}
and here is my code :
const transcribeRecordedVoice = async (recordedURI: any, languageISO: string | null) => {
return new Promise<string>((resolve, reject) => {
try {
if (!recordedURI) {
reject('No recorded URI');
return;
}
const formData = new FormData();
// IMPORTANT: Do not change the below code even it has an error.
// Turning the second param into "string" causes an error in API calling.
// @ts-ignore
formData.append('file', {
uri: recordedURI,
name: 'sound.m4a',
type: 'audio/m4a',
});
formData.append('model', 'whisper-1');
if (languageISO) {
formData.append('language', languageISO);
}
axios
.post('https://api.openai.com/v1/audio/transcriptions', formData, {
headers: {
'Content-Type': 'multipart/form-data',
Authorization: Bearer ${whisperAPIKey},
},
timeout: 50000,
})
.then((res) => {
setTranscribedText(res.data.text);
resolve(res.data.text);
})
.catch((err) => {
reject(err);
logger(err, 'transcribeRecordedVoice()');
});
} catch (error) {
reject(error);
logger(error, 'transcribeRecordedVoice()');
}
});
};
Any help would be appreciated
Thanks!