Batches and Scripts
One file is a demo. Real work arrives as a folder: a semester of lectures, a season of club meetings, a shoebox of family cassettes. This chapter scales from one file to many, honestly about where the time goes.
Many files, one command
The command takes any number of files:
whisper talk1.mp3 talk2.mp3 talk3.mp3 \
--model base --output_dir transcripts
Each file is detected, transcribed and written out in turn (the lab ran two clips this way, transcript t07, and got the full set of five formats for each). Shell wildcards do the collecting:
whisper recordings/*.mp3 --model base \
--output_dir transcripts
This is the right tool for a handful of long files — an hour of audio keeps the machine busy far longer than starting the program does. Which brings up the opposite case.
The load-once problem
Every whisper command pays a startup
cost: Python, PyTorch and the model all
load before the first word is heard. In
the lab that cost dominated every short
run (chapter 5) — 35 seconds of wall
clock for eleven seconds of audio.
Fifty short clips, run one command at a
time, means paying it fifty times.
The fix is to load the model once and
feed it files from a small Python
script. This one is in examples/ and
was run for real in the lab
(transcript t08):
import whisper
model = whisper.load_model("tiny")
for path in sorted(Path("in").iterdir()):
result = model.transcribe(str(path))
Path("out", path.stem + ".txt").write_text(
result["text"].strip() + "\n")
(The shipped script adds file-type
filtering and timing; the shape above is
the whole idea.) Measured: the model
loaded in about a second once warm, then
transcribed the lab's three clips —
eleven, thirty and sixty seconds — in
5, 13 and 16 seconds each. No repeated
startup, and the detected language
arrives in result["language"] for
free.
One honest footnote: the script's JFK text came back with slightly different punctuation than the command-line run of the same clip and model ("Americans ask not" instead of "Americans, ask not"). Small decode variations between runs are normal; the words are stable, the commas less so. Proofread anything quoted.
Which shape when
- A few long files: the plain command with several file names. Done.
- Many files, or short ones: the load-once script.
- A standing routine (every new recording in a folder gets transcribed overnight): the script, run by your system's scheduler — and consider chapter 9's faster engine first, because at folder scale its speed difference stops being a curiosity and starts being the schedule.
Check: run the folder script over three clips you have already transcribed by command, and confirm you get three text files whose words match the earlier output.