ashishkblink commited on
Commit
1219672
·
verified ·
1 Parent(s): e86d473

Upload f5_tts/eval/eval_librispeech_test_clean.py with huggingface_hub

Browse files
f5_tts/eval/eval_librispeech_test_clean.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Evaluate with Librispeech test-clean, ~3s prompt to generate 4-10s audio (the way of valle/voicebox evaluation)
2
+
3
+ import sys
4
+ import os
5
+ import argparse
6
+
7
+ sys.path.append(os.getcwd())
8
+
9
+ import multiprocessing as mp
10
+ from importlib.resources import files
11
+
12
+ import numpy as np
13
+
14
+ from f5_tts.eval.utils_eval import (
15
+ get_librispeech_test,
16
+ run_asr_wer,
17
+ run_sim,
18
+ )
19
+
20
+ rel_path = str(files("f5_tts").joinpath("../../"))
21
+
22
+
23
+ def get_args():
24
+ parser = argparse.ArgumentParser()
25
+ parser.add_argument("-e", "--eval_task", type=str, default="wer", choices=["sim", "wer"])
26
+ parser.add_argument("-l", "--lang", type=str, default="en")
27
+ parser.add_argument("-g", "--gen_wav_dir", type=str, required=True)
28
+ parser.add_argument("-p", "--librispeech_test_clean_path", type=str, required=True)
29
+ parser.add_argument("-n", "--gpu_nums", type=int, default=8, help="Number of GPUs to use")
30
+ parser.add_argument("--local", action="store_true", help="Use local custom checkpoint directory")
31
+ return parser.parse_args()
32
+
33
+
34
+ def main():
35
+ args = get_args()
36
+ eval_task = args.eval_task
37
+ lang = args.lang
38
+ librispeech_test_clean_path = args.librispeech_test_clean_path # test-clean path
39
+ gen_wav_dir = args.gen_wav_dir
40
+ metalst = rel_path + "/data/librispeech_pc_test_clean_cross_sentence.lst"
41
+
42
+ gpus = list(range(args.gpu_nums))
43
+ test_set = get_librispeech_test(metalst, gen_wav_dir, gpus, librispeech_test_clean_path)
44
+
45
+ ## In LibriSpeech, some speakers utilized varying voice characteristics for different characters in the book,
46
+ ## leading to a low similarity for the ground truth in some cases.
47
+ # test_set = get_librispeech_test(metalst, gen_wav_dir, gpus, librispeech_test_clean_path, eval_ground_truth = True) # eval ground truth
48
+
49
+ local = args.local
50
+ if local: # use local custom checkpoint dir
51
+ asr_ckpt_dir = "../checkpoints/Systran/faster-whisper-large-v3"
52
+ else:
53
+ asr_ckpt_dir = "" # auto download to cache dir
54
+ wavlm_ckpt_dir = "../checkpoints/UniSpeech/wavlm_large_finetune.pth"
55
+
56
+ # --------------------------- WER ---------------------------
57
+ if eval_task == "wer":
58
+ wers = []
59
+ with mp.Pool(processes=len(gpus)) as pool:
60
+ args = [(rank, lang, sub_test_set, asr_ckpt_dir) for (rank, sub_test_set) in test_set]
61
+ results = pool.map(run_asr_wer, args)
62
+ for wers_ in results:
63
+ wers.extend(wers_)
64
+
65
+ wer = round(np.mean(wers) * 100, 3)
66
+ print(f"\nTotal {len(wers)} samples")
67
+ print(f"WER : {wer}%")
68
+
69
+ # --------------------------- SIM ---------------------------
70
+ if eval_task == "sim":
71
+ sim_list = []
72
+ with mp.Pool(processes=len(gpus)) as pool:
73
+ args = [(rank, sub_test_set, wavlm_ckpt_dir) for (rank, sub_test_set) in test_set]
74
+ results = pool.map(run_sim, args)
75
+ for sim_ in results:
76
+ sim_list.extend(sim_)
77
+
78
+ sim = round(sum(sim_list) / len(sim_list), 3)
79
+ print(f"\nTotal {len(sim_list)} samples")
80
+ print(f"SIM : {sim}")
81
+
82
+
83
+ if __name__ == "__main__":
84
+ main()