This is my code on client side:
const formData = (blob: Blob) => {
const body = new FormData();
const file = new File([blob], "speech.mp3", { type: "audio/m4a" });
body.append("file", file);
body.append("model", "gpt-4o-mini-transcribe");
body.append("language", "en");
body.append("response_format", "json");
return body;
};
const sendAudio = async ( ) => {
try {
const response = await fetch(
"https://api.openai.com/v1/audio/transcriptions",
{
method: "POST",
body: formData(blob),
headers: {
Authorization: `Bearer ...`,
},
},
);
const json = await response.json();
return json
} catch {
return "";
}
};
And getting this error
{
"message": "Audio file might be corrupted or unsupported",
"type": "invalid_request_error",
"param": "file",
"code": "invalid_value"
}
What am I doing wrong?