Spaces:
Sleeping
Sleeping
Merge pull request #3 from Masao-Someki/feature/add_per
Browse files- evaluation/svs_eval.py +45 -5
evaluation/svs_eval.py
CHANGED
|
@@ -7,7 +7,6 @@ from pathlib import Path
|
|
| 7 |
|
| 8 |
# ----------- Initialization -----------
|
| 9 |
|
| 10 |
-
|
| 11 |
def init_singmos():
|
| 12 |
print("[Init] Loading SingMOS...")
|
| 13 |
return torch.hub.load(
|
|
@@ -23,7 +22,17 @@ def init_basic_pitch():
|
|
| 23 |
|
| 24 |
|
| 25 |
def init_per():
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def init_audiobox_aesthetics():
|
|
@@ -72,10 +81,41 @@ def compute_dissonance_rate(intervals, dissonant_intervals={1, 2, 6, 10, 11}):
|
|
| 72 |
return np.mean(dissonant) if intervals else np.nan
|
| 73 |
|
| 74 |
|
| 75 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
audio_array, sr = librosa.load(audio_path, sr=16000)
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
def eval_aesthetic(audio_path, predictor):
|
|
|
|
| 7 |
|
| 8 |
# ----------- Initialization -----------
|
| 9 |
|
|
|
|
| 10 |
def init_singmos():
|
| 11 |
print("[Init] Loading SingMOS...")
|
| 12 |
return torch.hub.load(
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def init_per():
|
| 25 |
+
print("[Init] Loading PER...")
|
| 26 |
+
from transformers import pipeline
|
| 27 |
+
import jiwer
|
| 28 |
+
asr_pipeline = pipeline(
|
| 29 |
+
"automatic-speech-recognition",
|
| 30 |
+
model="openai/whisper-large-v3-turbo"
|
| 31 |
+
)
|
| 32 |
+
return {
|
| 33 |
+
"asr_pipeline": asr_pipeline,
|
| 34 |
+
"jiwer": jiwer,
|
| 35 |
+
}
|
| 36 |
|
| 37 |
|
| 38 |
def init_audiobox_aesthetics():
|
|
|
|
| 81 |
return np.mean(dissonant) if intervals else np.nan
|
| 82 |
|
| 83 |
|
| 84 |
+
def pypinyin_g2p_phone_without_prosody(text):
|
| 85 |
+
from pypinyin import Style, pinyin
|
| 86 |
+
from pypinyin.style._utils import get_finals, get_initials
|
| 87 |
+
|
| 88 |
+
phones = []
|
| 89 |
+
for phone in pinyin(text, style=Style.NORMAL, strict=False):
|
| 90 |
+
initial = get_initials(phone[0], strict=False)
|
| 91 |
+
final = get_finals(phone[0], strict=False)
|
| 92 |
+
if len(initial) != 0:
|
| 93 |
+
if initial in ["x", "y", "j", "q"]:
|
| 94 |
+
if final == "un":
|
| 95 |
+
final = "vn"
|
| 96 |
+
elif final == "uan":
|
| 97 |
+
final = "van"
|
| 98 |
+
elif final == "u":
|
| 99 |
+
final = "v"
|
| 100 |
+
if final == "ue":
|
| 101 |
+
final = "ve"
|
| 102 |
+
phones.append(initial)
|
| 103 |
+
phones.append(final)
|
| 104 |
+
else:
|
| 105 |
+
phones.append(final)
|
| 106 |
+
return phones
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def eval_per(audio_path, reference_text, evaluator=None):
|
| 110 |
audio_array, sr = librosa.load(audio_path, sr=16000)
|
| 111 |
+
asr_result = evaluator['asr_pipeline'](
|
| 112 |
+
audio_array,
|
| 113 |
+
generate_kwargs={"language": "mandarin"}
|
| 114 |
+
)['text']
|
| 115 |
+
hyp_pinyin = pypinyin_g2p_phone_without_prosody(asr_result)
|
| 116 |
+
ref_pinyin = pypinyin_g2p_phone_without_prosody(reference_text)
|
| 117 |
+
per = evaluator['jiwer'].wer(ref_pinyin, hyp_pinyin)
|
| 118 |
+
return {"per": per}
|
| 119 |
|
| 120 |
|
| 121 |
def eval_aesthetic(audio_path, predictor):
|