Saturday 3 June 2023

How with OpenAI Whisper do I transcribe all mp4s in a folder?

Problem:

I'd like to transcribe all mp4 files in a folder on both Mac and Windows using Whisper.

I am familiar with scripting and command-line, and have already set up Whisper to work on my machine.


Windows example solution:

The following is an example solution for Windows. Save this in a .bat file and run it in the folder you'd like to process all mp4 files. Modify the script as you need to.

This example transcribes in English with Whisper set up to use CUDA. It skips over any already transcribed mp4 files. It is not recursive.


e.g. transcribe_all_mp4.bat:
for %%f in (*.mp4) do (
	echo %%~nf
	if not exist "%%~nf.txt" (
		echo will process %%~nf.mp4
		whisper "%%~nf.mp4" --language English --device cuda
	) else (
		echo will NOT process %%~nf.mp4
	)
)

Mac example solution:

The following example is a single Terminal command you can use in MacOS with Whisper already set up.

Note that this example command does not check for existing transcriptions. It does however specify Whisper to use the medium model. It is not recursive. Modify the command as you need to.

In Terminal in the folder where you want to transcribe your .mp4 files:

for f in *.mp4 ; do whisper $f --model medium ; done

Notes:

The above solutions in Windows and Mac were verified to work between February 2023 to June 2023 (for real-life conference and film work). As of this time the good folks over at Whisper haven't yet implemented batch processing of files.

Hope these examples helped you start to get past where you too got stuck :)


References: