yum-archive/TaSTT-Whisper

High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model

git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper

yumbegin work disabling vadaaa0188

master
1.6 KiB49 linesraw
1import argparse
2import editdistance
3import re
4import subprocess
5import sys
6import time
7
8from whisper.normalizers import EnglishTextNormalizer
9
10if __name__ == "__main__":
11    parser = argparse.ArgumentParser()
12    parser.add_argument("reference_path", type=str, help="Path to reference transcript")
13    parser.add_argument("audio_path", type=str, help="Path to audio file to transcribe")
14    parser.add_argument("model_path", type=str, help="Path to Whisper model to use")
15    parser.add_argument("decode_method", type=str, help="Decoding method. Either 'greedy' or 'beam'")
16    args = parser.parse_args()
17
18    cmd = "./WhisperCLI.exe"
19    cmd_args = [
20            "--audio_path", args.audio_path,
21            "--model_path", args.model_path,
22            "--decode_method", args.decode_method,
23            ]
24
25    t0 = time.time()
26    result = subprocess.run([cmd] + cmd_args, stdout=subprocess.PIPE)
27    t1 = time.time()
28
29    if result.returncode != 0:
30        print(f"Failed to transcribe: cmd returned {result.returncode}",
31                file=sys.stderr)
32
33    test_transcript = result.stdout.decode("utf-8")
34    with open(args.reference_path, "r") as f:
35        ref_transcript = f.read()
36
37    # Normalize transcripts before computing edit distance (as described in
38    # whisper paper).
39    normalize = EnglishTextNormalizer()
40    test_transcript = normalize(test_transcript)
41    ref_transcript = normalize(ref_transcript)
42
43    dist = editdistance.eval(ref_transcript, test_transcript)
44
45    print(f"Duration: {t1 - t0}")
46    print(f"Levenshtein distance: {dist}")
47    print(f"Control: {ref_transcript}")
48    print(f"Experiment: {test_transcript}")
49