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