-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.py
executable file
·65 lines (52 loc) · 1.79 KB
/
bench.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import argparse
import models.whisper as whisper
import models.canary as canary
import os
import logging
import subprocess
import pathlib
# log config
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(
prog="bench.py",
description="Use this program to test the different models and audio transformations against audio files.",
epilog="cleeb.",
)
parser.add_argument("filename")
parser.add_argument("-n", "--normalize", action="store_true")
args = parser.parse_args()
def compare(file):
if args.normalize:
# Define the input and output file paths
input_file = file
output_file = pathlib.Path(file).stem + ".normalized.wav"
# Define the speechnorm filter string
speechnorm_filter = "speechnorm=e=25:r=0.0001:l=1"
# Construct the FFmpeg command
ffmpeg_command = [
"ffmpeg",
"-i",
input_file,
"-af",
speechnorm_filter,
output_file,
]
# Execute the FFmpeg command
subprocess.run(ffmpeg_command, check=True)
file = output_file
whisper_transcript = whisper.transcribe(file, cleanup=False)
canary_transcript = canary.transcribe(file, cleanup=False)
logging.info("===================================================")
logging.info(f"New Transcription: {file}")
logging.info(f"Whisper Transcription: {whisper_transcript}")
logging.info(f"Canary Transcription: {canary_transcript}")
logging.info(f"Normalized?: {args.normalize}")
if os.path.isdir(args.filename):
files = os.listdir(args.filename)
for file in files:
path = os.path.abspath(os.path.join(args.filename, file))
compare(path)
else:
logging.info(args.filename)
compare(args.filename)