I performed a recording with expo-av and on my device i get the following uri as result:
file:///var/mobile/Containers/Data/Application/5DCEDD6B-24B5-4A69-92E8-1FB910ABFD7D/Library/Caches/ExponentExperienceData/@anonymous/test_stack-9c4d24a8-f364-45ab-aa8f-a9e42009003a/AV/recording-30CCB12D-40F2-44D7-B9E3-8DB1389F4E8F.m4a
i am trying to send the file to whisper api in order to get the transcription and here’s what i am doing:
const audioBuffer = await FileSystem.readAsStringAsync(uri, {
encoding: FileSystem.EncodingType.Base64,
});
const form = new FormData();
form.append('file', audioBuffer);
form.append("model", "whisper-1");
const response = await axios.post(
'https://api.openai.com/v1/audio/transcriptions',
form, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'multipart/form-data',
},
}
);
but i get a general error 400 with no additional information.
i tried also the send the uri as it is in the file but same issue.
If i use the OpenAI import and execute the code:
const openai = new OpenAI(
{apiKey: process.env.EXPO_PUBLIC_OPENAI_API_KEY,
}
);
const audioBuffer = await FileSystem.readAsStringAsync(uri, {
encoding: FileSystem.EncodingType.Base64,
});
const transcription = await openai.audio.transcriptions.create({
file: audioBuffer,
model: "whisper-1",
});
i got instead the error:
Error: [Error: 400 1 validation error for Request
body -> file
Expected UploadFile, received: <class 'str'> (type=value_error)]
any idea?
thanks
stefano