For the transcription of audio recordings, I use the following command:
fish -c 'echo $fish_pid > ~/.kill_pid;exec arecord -f cd' | \
curl --url https://api.openai.com/v1/audio/transcriptions \
--request POST \
--header "Authorization: Bearer $OPENAI_API_KEY" \
--header "Content-Type: multipart/form-data" \
--form file=@-\;filename=f.wav \
--form model=gpt-4o-mini-transcribe \
--form response_format=text
Explanation
The first command of the pipe (fish -c ...) starts the audio recorder arecord that records from the mic in audio/wav format and streams the recorded audio data to stdout (until it is manually killed by a SIGTERM using the PID in ~/.kill_pid).
The second command of the pipe (curl) uploads the audio data to the transcription endpoint of OpenAI. The endpoint receives the data in the structure of an HTML form and expects besides the actual data a filename with a suffix (in my case: f.wav) to detect the format of the audio data transmitted. Hence, the curl parameter: --form file=@-\;filename=f.wav
The problem
The problem is that curl does not start the transmission/upload of the data until the pipe closes. It seems that curl badly wants to set the Content-Length header for which it needs to know the length of all file data to send. But I want the data to be uploaded continuously while the audio is being recorded, so I don't need to wait for the upload after the recording is terminated. (So, I don't care about the Content-Length header; just want my audio data to be being transmitted while the data is being created/recorded.)
Is there a tool or a library that allows to do that?
(Or maybe just another magic parameter to curl?)
What didn't work out so far
httpiedoes not recognize-as a file specifier forstdin. Specifying/dev/stdinruns into the problem: (a) it does not know the additionalfilename=f.wavspecifier, (b) exchanging it fortype=audio/wavreturnsRequest body (from stdin, --raw or a file) and request data (key=value) cannot be mixed.- The http libraries of python and perl do not accept stdin for form-POSTING of file data.
(No matter what AI assistants may claim.)
--ignore-stdinto avoid the “cannot be mixed” error.http: error: OSError: [Errno 29] Illegal seek- as you already pointed out in a comment to my other question. Thx.