mirror of
https://github.com/ml-explore/mlx-examples.git
synced 2025-09-01 04:14:38 +08:00
fix bugs, add test coverage
This commit is contained in:
@@ -232,7 +232,6 @@ def main():
|
|||||||
if audio_obj == "-":
|
if audio_obj == "-":
|
||||||
# receive the contents from stdin rather than read a file
|
# receive the contents from stdin rather than read a file
|
||||||
audio_obj = audio.load_audio(from_stdin=True)
|
audio_obj = audio.load_audio(from_stdin=True)
|
||||||
output_name_template = "content"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = transcribe(
|
result = transcribe(
|
||||||
|
@@ -7,16 +7,44 @@ TEST_OUTPUT_DIR=$(mktemp -d -t mlx_whisper_cli_test)
|
|||||||
|
|
||||||
# the control output - cli called with audio position arg
|
# the control output - cli called with audio position arg
|
||||||
# expected output file name is ls_test.json
|
# expected output file name is ls_test.json
|
||||||
|
TEST_OUTPUT_NAME_FOR_ALL="--output-name arg is used for all output formats"
|
||||||
mlx_whisper "$TEST_AUDIO" \
|
mlx_whisper "$TEST_AUDIO" \
|
||||||
--output-dir "$TEST_OUTPUT_DIR" \
|
--output-dir "$TEST_OUTPUT_DIR" \
|
||||||
--output-format all \
|
--output-format all \
|
||||||
--output-name '{basename}_transcribed' \
|
--output-name '{basename}_transcribed' \
|
||||||
--temperature 0 \
|
--temperature 0 \
|
||||||
--verbose=False
|
--verbose=False
|
||||||
/bin/ls ${TEST_OUTPUT_DIR}/ls_test_transcribed.{json,srt,tsv,txt,vtt} | sort
|
if /bin/ls ${TEST_OUTPUT_DIR}/ls_test_transcribed.{json,srt,tsv,txt,vtt} > /dev/null; then
|
||||||
|
echo "[PASS] $TEST_OUTPUT_NAME_FOR_ALL"
|
||||||
|
else
|
||||||
|
echo "[FAIL] $TEST_OUTPUT_NAME_FOR_ALL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
TEST_OUTPUT_NAME_TEMPLATE="testing the output name template usage scenario"
|
||||||
|
for test_val in $(seq 10 10 60); do
|
||||||
|
mlx_whisper "$TEST_AUDIO" \
|
||||||
|
--output-name "{basename}_mwpl_${test_val}" \
|
||||||
|
--output-dir "$TEST_OUTPUT_DIR" \
|
||||||
|
--output-format srt \
|
||||||
|
--max-words-per-line $test_val \
|
||||||
|
--word-timestamps True \
|
||||||
|
--verbose=False
|
||||||
|
TEST_DESC="testing output name template while varying --max-words-per-line=${test_val}"
|
||||||
|
if /bin/ls $TEST_OUTPUT_DIR/ls_test_mwpl_${test_val}.srt > /dev/null; then
|
||||||
|
echo "[PASS] $TEST_DESC"
|
||||||
|
else
|
||||||
|
echo "[FAIL] $TEST_DESC"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
TEST_STDIN_1="mlx_whisper produces identical output whether provided audio arg or stdin of same content"
|
TEST_STDIN_1="mlx_whisper produces identical output whether provided audio arg or stdin of same content"
|
||||||
/bin/cat "$TEST_AUDIO" | mlx_whisper - --output-dir "$TEST_OUTPUT_DIR" --output-format json --temperature 0 --verbose=False
|
/bin/cat "$TEST_AUDIO" | mlx_whisper - \
|
||||||
|
--output-dir "$TEST_OUTPUT_DIR" \
|
||||||
|
--output-format json \
|
||||||
|
--temperature 0 \
|
||||||
|
--verbose=False
|
||||||
if diff "${TEST_OUTPUT_DIR}/content.json" "${TEST_OUTPUT_DIR}/ls_test_transcribed.json"; then
|
if diff "${TEST_OUTPUT_DIR}/content.json" "${TEST_OUTPUT_DIR}/ls_test_transcribed.json"; then
|
||||||
echo "[PASS] $TEST_STDIN_1"
|
echo "[PASS] $TEST_STDIN_1"
|
||||||
else
|
else
|
||||||
@@ -25,7 +53,12 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
TEST_STDIN_2="mlx_whisper produces identical output when stdin comes via: cmd < file"、
|
TEST_STDIN_2="mlx_whisper produces identical output when stdin comes via: cmd < file"、
|
||||||
mlx_whisper - --output-name '{basename}_transcribed' --output-dir "$TEST_OUTPUT_DIR" --output-format tsv --temperature 0 --verbose=False < "$TEST_AUDIO"
|
mlx_whisper - \
|
||||||
|
--output-name '{basename}_transcribed' \
|
||||||
|
--output-dir "$TEST_OUTPUT_DIR" \
|
||||||
|
--output-format tsv \
|
||||||
|
--temperature 0 \
|
||||||
|
--verbose=False < "$TEST_AUDIO"
|
||||||
if diff "${TEST_OUTPUT_DIR}/content_transcribed.tsv" "${TEST_OUTPUT_DIR}/ls_test_transcribed.tsv"; then
|
if diff "${TEST_OUTPUT_DIR}/content_transcribed.tsv" "${TEST_OUTPUT_DIR}/ls_test_transcribed.tsv"; then
|
||||||
echo "[PASS] $TEST_STDIN_2"
|
echo "[PASS] $TEST_STDIN_2"
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user