Skip to content

[whisper] mlx_whisper CLI overwrites output file when multiple audio inputs are provided #1441

Description

@bryzgaloff

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

  1. Run mlx_whisper file1.mp3 file2.mp3
  2. Check the output directory.
  3. 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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions