We have a requirement to provide MP3toTXT transcriptions using OpenAI. We use OpenAI for a bunch of stuff, but can't seem to get this working.
Here are the curl specs from OpenAI:
Here is what I have so far:
This is returning Error code 400 (Bad request). It should be working... hmm... I actually sent the code to OpenAI for debugging and it was verified :} Going nuts now!
What am I missing?
Here are the curl specs from OpenAI:
Code:
curl --request POST --url [URL unfurl="true"]https://api.openai.com/v1/audio/transcriptions[/URL] --header "Authorization: Bearer $OPENAI_API_KEY" --header 'Content-Type: multipart/form-data' --form file=@/path/to/file/audio.mp3 --form model=whisper-1
Here is what I have so far:
Code:
LOCAL lcApiKey, lcBoundary, lcFile, lcContent, lcFileName, lcName, lcName, lcModel, lcRequest
#DEFINE CRLF CHR(13) + CHR(10)
lcApiKey = "OpenAI-Key-Here[b][/b]"
lcBoundary = "--" + STRTRAN(SYS(2015), "_" ,"")
lcFile = "c:\temp\audio.mp3"
lcContent = FILETOSTR(lcFile)
lcFileName = JUSTFNAME(lcFile)
lcName = "file"
lcName2 = "model"
lcModel = "whisper-1"
lcRequest = lcBoundary + CRLF + TEXTMERGE([Content-Disposition: form-data; name="<<[b]lcName[/b][i][/i]>>"; filename="<<[b]lcFileName[/b][i][/i]>>"]) + CRLF + ;
"Content-Type: application/octet-stream" + CRLF + CRLF + lcContent + CRLF + lcBoundary + CRLF + ;
TEXTMERGE([Content-Disposition: form-data; name="<<[b]lcName2[/b][i][/i]>>"]) + CRLF + CRLF + lcModel + CRLF + lcBoundary + "--"
[b]?GetOpenAIResponseSTT(lcBoundary, lcApiKey, lcRequest)[/b]
PROCEDURE GetOpenAIResponseSTT(tcBoundary AS String, tcApiKey AS String, tcRequest AS String) AS String
LOCAL lcURL, lcResponse, loHTTP
lcURL = "[URL unfurl="true"]https://api.openai.com/v1/audio/transcriptions"[/URL]
loHTTP = CREATEOBJECT("MSXML2.ServerXMLHTTP.6.0")
loHTTP.Open("POST", lcURL, .F.)
loHTTP.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + SUBSTR(tcBoundary, 3))
loHTTP.setRequestHeader("Authorization", "Bearer " + tcApiKey)
loHTTP.Send(tcRequest)
IF loHTTP.Status = 200
lcResponse = loHTTP.responseText
ELSE
lcResponse = "Error: " + TRANSFORM(loHTTP.Status)
ENDIF
RETURN lcResponse
ENDPROC
This is returning Error code 400 (Bad request). It should be working... hmm... I actually sent the code to OpenAI for debugging and it was verified :} Going nuts now!
What am I missing?