Describe the bug
When passing multiple audio files to the mlx_whisper CLI (e.g., mlx_whisper file1.mp3 file2.mp3), all transcriptions are written to the output file of the first input (file1.txt), sequentially overwriting it.
To Reproduce
- Run
mlx_whisper file1.mp3 file2.mp3
- Check the output directory.
- Observe that only
file1.txt exists and contains the transcription of file2.mp3 (the last processed file). file2.txt is not created.
Expected behavior
Each audio input should produce its own output file (file1.txt, file2.txt, etc.).
Root Cause
In whisper/mlx_whisper/cli.py, output_name is mutated inside the audio loop:
output_name: str = args.pop("output_name")
...
for audio_obj in args.pop("audio"):
if audio_obj == "-":
audio_obj = audio.load_audio(from_stdin=True)
output_name = output_name or "content"
else:
output_name = output_name or pathlib.Path(audio_obj).stem
try:
result = transcribe(...)
writer(result, output_name, **writer_args)
On the first iteration, output_name is reassigned to "file1". In subsequent iterations, output_name or pathlib.Path(...) evaluates to "file1", causing all remaining audio files to be written to file1.txt.
Proposed Fix
Use a local variable (e.g., file_output_name) inside the loop rather than reassigning output_name:
for audio_obj in args.pop("audio"):
if audio_obj == "-":
audio_obj = audio.load_audio(from_stdin=True)
file_output_name = output_name or "content"
else:
file_output_name = output_name or pathlib.Path(audio_obj).stem
try:
result = transcribe(
audio_obj,
path_or_hf_repo=path_or_hf_repo,
**args,
)
writer(result, file_output_name, **writer_args)
Describe the bug
When passing multiple audio files to the
mlx_whisperCLI (e.g.,mlx_whisper file1.mp3 file2.mp3), all transcriptions are written to the output file of the first input (file1.txt), sequentially overwriting it.To Reproduce
mlx_whisper file1.mp3 file2.mp3file1.txtexists and contains the transcription offile2.mp3(the last processed file).file2.txtis not created.Expected behavior
Each audio input should produce its own output file (
file1.txt,file2.txt, etc.).Root Cause
In
whisper/mlx_whisper/cli.py,output_nameis mutated inside theaudioloop:On the first iteration,
output_nameis reassigned to"file1". In subsequent iterations,output_name or pathlib.Path(...)evaluates to"file1", causing all remaining audio files to be written tofile1.txt.Proposed Fix
Use a local variable (e.g.,
file_output_name) inside the loop rather than reassigningoutput_name: