Skip to content

Commit 9820718

Browse files
committed
Demo seek fix for Whisper
1 parent 7ddca42 commit 9820718

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

whisper/demo_seek_fix.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
"""Demo: transcribe short audio with whisper-base.en to test seek behavior."""
3+
4+
import os
5+
import string
6+
import urllib.request
7+
import mlx_whisper
8+
9+
# Download test audio
10+
audio = "LJ037-0171.wav"
11+
if not os.path.exists(audio):
12+
urllib.request.urlretrieve(f"https://keithito.com/LJ-Speech-Dataset/{audio}", audio)
13+
14+
# Expected transcription
15+
expected = "The examination and testimony of the experts enabled the commission to conclude that five shots may have been fired"
16+
17+
# Transcribe
18+
result = mlx_whisper.transcribe(audio, path_or_hf_repo="mlx-community/whisper-base.en-mlx")
19+
20+
# Compute accuracy
21+
strip = str.maketrans("", "", string.punctuation)
22+
expected_words = set(expected.lower().translate(strip).split())
23+
actual_words = set(result["text"].lower().translate(strip).split())
24+
accuracy = len(expected_words & actual_words) / len(expected_words) * 100
25+
26+
# Output
27+
print(f"Expected: {expected}")
28+
print(f"Actual: {result['text'].strip()}")
29+
print(f"Accuracy: {accuracy:.0f}%")
30+
print(f"Segments: {len(result['segments'])}")
31+
for s in result["segments"]:
32+
print(f" [{s['start']:.2f}s - {s['end']:.2f}s]{s['text']}")

0 commit comments

Comments
 (0)