I've been working tirelessly through the night, trying to record myself on my iPhone using expo-av to capture speech and then upload it to openai's transcriptions endpoint with the whisper-1 model.
The recording is saved as an mp4 file, which I then convert into a base64 string. I have verified that the base64 content corresponds to an mp4 format:
Tool for converting base64 to file
https://i.sstatic.net/vTXty.png
Tool for uploading and checking the file
https://i.sstatic.net/UuxTn.png
Below is the react-native code snippet:
const recordingOptions = {
android: {
extension: ".mp4",
outputFormat: Audio.AndroidOutputFormat.MPEG_4,
audioEncoder: Audio.AndroidAudioEncoder.AAC,
sampleRate: 44100,
numberOfChannels: 2,
bitRate: 128000,
},
ios: {
extension: ".mp4",
// outputFormat: Audio.IOSOutputFormat.MPEG4AAC,
audioQuality: Audio.IOSAudioQuality.HIGH,
sampleRate: 44100,
numberOfChannels: 2,
bitRate: 128000,
},
web: {
mimeType: "audio/mp4",
bitsPerSecond: 128000 * 8,
},
};
Current implementation:
const recordingUri = recording.getURI();
const recordingBase64 = await ExpoFileSystem.readAsStringAsync(
recordingUri,
{
encoding: ExpoFileSystem.EncodingType.Base64,
}
);
const languageCode = "en"; // English
console.log(languageCode);
console.log(recordingBase64)
const buffer = Buffer.from(recordingBase64, "base64")
const blob= new Blob([buffer], { type:'audio/mp4' })
const file = new File([blob],'test.mp4', {type:'audio/mp4'})
const formData = new FormData();
formData.append('file',file);
formData.append("model", "whisper-1");
const apiUrl = "https://api.openai.com/v1/audio/transcriptions";
const requestOptions = {
method: "POST",
headers: {
Authorization: `Bearer ${OPENAI_API_KEY}`,
},
body: formData,
};
fetch(apiUrl, requestOptions)
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.log(error));
However, every time I receive the following response:
{"error": {"code": null, "message": "Invalid file format. Supported formats: ['m4a', 'mp3', 'webm', 'mp4', 'mpga', 'wav', 'mpeg']", "param": null, "type": "invalid_request_error"}}
Any insights on what might be going wrong here?