Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions whisper/mlx_whisper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,16 @@ def main():
# receive the contents from stdin rather than read a file
audio_obj = audio.load_audio(from_stdin=True)

output_name = output_name or "content"
file_output_name = output_name or "content"
else:
output_name = output_name or pathlib.Path(audio_obj).stem
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, output_name, **writer_args)
writer(result, file_output_name, **writer_args)
except Exception as e:
traceback.print_exc()
print(f"Skipping {audio_obj} due to {type(e).__name__}: {str(e)}")
Expand Down
42 changes: 42 additions & 0 deletions whisper/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
import tempfile
import unittest
from unittest.mock import Mock, patch

from mlx_whisper import cli


class TestCLI(unittest.TestCase):
def test_multiple_audio_files_get_distinct_output_names(self):
writer = Mock()
transcribe = Mock(return_value={"segments": []})

with tempfile.TemporaryDirectory() as output_dir:
argv = [
"mlx_whisper",
"first.mp3",
"second.mp3",
"--output-dir",
output_dir,
"--verbose",
"False",
]
with (
patch.object(cli, "get_writer", return_value=writer),
patch.object(cli, "transcribe", transcribe),
patch.object(sys, "argv", argv),
):
cli.main()

self.assertEqual(
[call.args[1] for call in writer.call_args_list],
["first", "second"],
)
self.assertEqual(
[call.args[0] for call in transcribe.call_args_list],
["first.mp3", "second.mp3"],
)


if __name__ == "__main__":
unittest.main()