fix bugs, add test coverage

This commit is contained in:
Anthony Wu 2024-10-03 15:45:48 -10:00
parent b6435dc9cc
commit 7b818c0d39
2 changed files with 36 additions and 4 deletions

View File

@ -232,7 +232,6 @@ def main():
if audio_obj == "-":
# receive the contents from stdin rather than read a file
audio_obj = audio.load_audio(from_stdin=True)
output_name_template = "content"
try:
result = transcribe(

View File

@ -7,16 +7,44 @@ TEST_OUTPUT_DIR=$(mktemp -d -t mlx_whisper_cli_test)
# the control output - cli called with audio position arg
# 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" \
--output-dir "$TEST_OUTPUT_DIR" \
--output-format all \
--output-name '{basename}_transcribed' \
--temperature 0 \
--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"
/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
echo "[PASS] $TEST_STDIN_1"
else
@ -25,7 +53,12 @@ else
fi
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
echo "[PASS] $TEST_STDIN_2"
else