Download scripts/eval_score.py from oProfM/LuaNovaV1: direct link, hf CLI and curl.
- Browser
- Download file 3.04 kB
-
https://huggingface.co/oProfM/LuaNovaV1/resolve/main/scripts/eval_score.py
- Command line
-
hf download hf://oProfM/LuaNovaV1/scripts/eval_score.py
-
curl -L -o eval_score.py https://huggingface.co/oProfM/LuaNovaV1/resolve/main/scripts/eval_score.py
3.04 kB
| """Score Lua Nova V1 eval WAVs with tts-eval judges (UTMOS22, SCOREQ, DNSMOS, Whisper WER/CER, ECAPA speaker sim). | |
| Run with experiments/tts-eval/.venv python after sourcing tts-eval/scripts/env.ps1. | |
| Speaker similarity uses a centroid built from the LuaNovaDataset test references (new voice), | |
| not the tts-eval F1 anchor. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import numpy as np | |
| sys.path.insert(0, r"C:\dev\AjudaEstudos\experiments\tts-eval\src") | |
| from tts_eval.classifiers import ClassifierSuite # noqa: E402 | |
| from tts_eval.env_setup import load_audio_dual_rate, split_windows # noqa: E402 | |
| EXP = Path(__file__).resolve().parents[1] | |
| EVAL = EXP / "eval" | |
| SUITE = Path(r"C:\dev\AjudaEstudos\experiments\tts-eval\suite\ptbr_eval_v1.json") | |
| def texts() -> dict[str, dict[str, str]]: | |
| test = {} | |
| for line in (EXP / "data/annotations/test.jsonl").read_text(encoding="utf-8").splitlines(): | |
| if line.strip(): | |
| r = json.loads(line) | |
| test[r["id"]] = r["text"] | |
| suite = json.loads(SUITE.read_text(encoding="utf-8")) | |
| return {"test": test, "stress_ptbr": {r["id"]: r["text"] for r in suite["stress_ptbr"]}} | |
| def main() -> None: | |
| clf = ClassifierSuite() | |
| txt = texts() | |
| ref_dir = EVAL / "reference" / "test" | |
| embs = [clf.spk.embed(load_audio_dual_rate(p)[2]) for p in sorted(ref_dir.glob("*.wav"))] | |
| centroid = np.mean(np.stack(embs), axis=0) | |
| results: dict = {} | |
| systems = ["reference"] + [d.name for d in sorted(EVAL.iterdir()) if d.is_dir() and d.name != "reference"] | |
| for system in systems: | |
| for split, tmap in txt.items(): | |
| d = EVAL / system / split | |
| if not d.exists(): | |
| continue | |
| rows = [] | |
| for wid, text in tmap.items(): | |
| p = d / f"{wid}.wav" | |
| if not p.exists(): | |
| continue | |
| _, _, w16 = load_audio_dual_rate(p) | |
| wins = split_windows(w16, win_sec=10.0, stride_sec=5.0) | |
| r = {"id": wid} | |
| r.update(clf.utmos.predict(wins)) | |
| r.update(clf.scoreq.predict(wins)) | |
| r.update(clf.dns.predict(w16)) | |
| asr = clf.asr.predict(w16, text) | |
| r.update({"wer": asr["wer"], "cer": asr["cer"], "asr_text": asr["asr_text"]}) | |
| r["speaker_sim"] = float(clf.spk.cosine_to_centroid(w16, centroid)) | |
| rows.append(r) | |
| keys = ["utmos22_mean", "scoreq_mean", "dns_ovr", "wer", "cer", "speaker_sim"] | |
| summary = {k: round(float(np.mean([x[k] for x in rows])), 4) for k in keys} | |
| summary["n"] = len(rows) | |
| results[f"{system}/{split}"] = {"summary": summary, "items": rows} | |
| print(system, split, summary, flush=True) | |
| (EVAL / "scores.json").write_text(json.dumps(results, indent=2, ensure_ascii=False), encoding="utf-8") | |
| print(json.dumps({k: v["summary"] for k, v in results.items()}, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |