I tried to use the Whisper API using JavaScript with a post request but did not work, so proceeded to do a curl request from Windows PowerShell with the following code and still did not work. I attach the error message.
Try removing the "Content-Type" = "multipart/form-data" header from your POST. I ran into a similar issue using the Rust library reqwest and removing that header fixed my issue.
could you please provide more of your code, have been at this for a few days now going crazy, I have something similar but still getting the invalid file format error
The “chunks” portion. I have a base64 encoded .wav file that works but I’ve tried every which way to feed the blob the data it always ends up corrupted. Would help a alot!
I’m using react-native, new to it but it’s a little more complicated than backend because you can’t use file system. I’ll give the library a try though!
When using Python, you need to input the binary form of the audio file. I initially failed, but later achieved success by modifying the code as follows.
with open(i, 'rb') as f:
file_content = f.read()
files = {
'file': (os.path.basename(i), file_content),
}
data = {
"model": "whisper-1",
"prompt": parse_prompt,
'response_format': "text"
}
hello
I’m trying to call /v1/audio/transcriptions by sending the audio.wav file through a multipart request in python but all the time I get the error “Could not parse multipart form”,
I do this
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3’,
‘Authorization’: ‘Bearer ’ + ai_key,
‘Content-Type’: f’multipart/form-data; boundary={boundary}’,
# ‘Content-Length’: str(len(body))
}
audio_file = ‘audio.wav’
with open(audio_file, ‘rb’) as file:
audio_data = file.read() #Payload
boundary = ‘----boundary----’
body = b’’
for field, value in fields:
body += f’–{boundary}\r\n’.encode()
body += f’Content-Disposition: form-data; name=“{field}”\r\n\r\n{value}\r\n’.encode()
Agregar el archivo adjunto al cuerpo de la petición
print(body)
mimetype = mimetypes.guess_type(audio_file)[0] or ‘application/octet-stream’
body += f’–{boundary}\r\n’.encode()
body += f’Content-Disposition: form-data; name=“audio”; filename=“{audio_file}”\r\n’.encode()
body += f’Content-Disposition: form-data; name=“file”; filename=“{audio_file}”\r\n’.encode()
body += f’Content-Type: {mimetype}\r\n\r\n’.encode()
body += audio_data + b’\r\n’
Crear una conexión HTTP a través del proxy
conn = http.client.HTTPSConnection(proxy_host, proxy_port)
…
thanks
regards
diego