New Tool Radar

Local AI

How to Save whisper-cli Output as JSON

Add -oj and -of to your whisper-cli command to save the transcription result as a JSON file you can open, search, and feed to another program.

Schematic diagram with three steps: build whisper.cpp and transcribe a 16-bit WAV file, add -oj and -of to save JSON output, and open the JSON file to read the result.

whisper-cli prints the transcript to the terminal, which is fine for reading once — but if another program needs the result, or you want to search it later, a printed transcript is the wrong shape. The tool can write the result to a JSON file instead: -oj turns JSON output on, and -of names the output file. This guide is about the JSON file output only; it is different from the subtitles guide, which saves timed .srt subtitles, and from the word-timestamps guide, which is about per-word timings inside the output.

Build and transcribe once

Build the project with the README’s own Quick start commands. The download script fetches the base.en model, and the build produces the whisper-cli tool under build/bin/:

git clone https://github.com/ggml-org/whisper.cpp.git
cd whisper.cpp
sh ./models/download-ggml-model.sh base.en
cmake -B build
cmake --build build -j --config Release

Transcribe the repository’s sample recording once, to confirm the tool works before you add output flags:

./build/bin/whisper-cli -f samples/jfk.wav

Note the README’s warning: whisper-cli currently runs only with 16-bit WAV files. Convert anything else first with ffmpeg, using the README’s own example:

ffmpeg -i input.mp3 -ar 16000 -ac 1 -c:a pcm_s16le output.wav

Add -oj and -of

The whisper-cli help page defines the output flags. -oj, --output-json outputs the result in a JSON file, and -of FNAME, --output-file FNAME sets the output file path (without file extension) — the tool adds the .json extension itself. Add both to the usual transcription command, naming the model and the file explicitly:

./build/bin/whisper-cli -m ./models/ggml-base.en.bin -f samples/jfk.wav -oj -of transcript

The help page gives the model flag as -m FNAME, --model FNAME, with a default of models/ggml-base.en.bin, and the file flag as -f FNAME, --file FNAME, the input audio file path. If the plain JSON does not carry enough detail for your next step, add -ojf, --output-json-full as well: the help page defines it as including more information in the JSON file.

Open the JSON file

The result lands in transcript.json next to where you ran the command. Open it in a text editor and read the transcript words in order, checking them against the recording at a few timestamps. To confirm the file is well-formed JSON, pretty-print it:

python3 -m json.tool transcript.json

If that command prints the file back out, the JSON parses cleanly and any program that reads JSON can take it from here — a search script, a subtitle converter, or a notes app. Compare the -oj file with the -ojf file if you ran both: the full version contains more information, so use it when the plain version is missing a field your next step needs.

Try it: four checks

Check What you should see If you do not see it
Flags The command includes both -oj and -of transcript Without -oj no JSON file is written — the transcript only prints to the terminal
File A file called transcript.json exists after the run Check the -of path — it takes the path without the extension, and the tool adds .json
Content The file opens as valid JSON and contains the transcript words Run python3 -m json.tool transcript.json — if it errors, the file was not written completely
Full Re-running with -ojf produces a file with more information than the -oj run Compare the two files — the full version is the one to use when the plain version lacks a field you need

Expected result. We checked the whisper.cpp README for the Quick start clone, download of base.en, and CMake build commands, the whisper-cli transcribe command on samples/jfk.wav, the 16-bit WAV note, and the ffmpeg conversion example; and the whisper-cli help page for the -oj, –output-json flag defined as output result in a JSON file, the -ojf, –output-json-full flag defined as include more information in the JSON file, the -of, –output-file flag defined as output file path (without file extension), the -m, –model flag with its models/ggml-base.en.bin default, and the -f, –file flag for the input audio file path. We did not run whisper.cpp or save any JSON.

Limits

The JSON file holds the model’s transcription result, which is still a guess — check it against the audio on material you care about, the same as you would a printed transcript. The -of path takes no extension; the tool adds .json itself, so do not write transcript.json as the -of value. Only 16-bit WAV input works, so convert other audio with ffmpeg first. This is the JSON file output, not the .srt subtitles output and not the word-timestamps output. We did not run whisper.cpp, so no JSON here is a recorded result.

Sources

See all