Created
March 13, 2023 02:43
-
-
Save allswellthatsmaxwell/7fafdb60a522f26ad780f21404873714 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I keep getting this response from the transcriptions endpoint: | |
{"error":{"message":"Invalid file format. | |
Supported formats: ['m4a', 'mp3', 'webm', 'mp4', 'mpga', 'wav', 'mpeg']", | |
"type":"invalid_request_error","param":null,"code":null}} | |
# But the blob I'm uploading has type mp4... I think? Here is the blob's console output: | |
{"_data":{"size":252408,"offset":0,"blobId":"716D0789-6787-4D4B-A60E-72AE30483195","type":"video/mp4", | |
"name":"recording-734C56FB-EB50-45C1-86CE-027AC71257F4.mp4","__collector":{}}} | |
# And here is the code where I'm logging both of those things: | |
const uri = recording.getURI(); | |
const file = await fetch(uri); | |
const blob = await file.blob(); | |
console.log("Blob type: ", blob.type, "Blob: ", blob); | |
const filename = uri.split('/').pop(); | |
const fileObj = new File([blob], filename); | |
const formData = new FormData(); | |
formData.append('file', fileObj); | |
formData.append('model', 'whisper-1'); | |
formData.append('response_format', 'text'); | |
formData.append('language', 'en'); | |
const response = await fetch('https://api.openai.com/v1/audio/transcriptions', { | |
method: 'POST', | |
headers: { | |
Authorization: `Bearer ${OPENAI_API_KEY}`, | |
'Content-Type': 'multipart/form-data', | |
}, | |
body: formData, | |
}); | |
console.log("Whisper API response: ", response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment