Download scripts/eval_asr_large.py from oProfM/LuaNovaV1: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/oProfM/LuaNovaV1/resolve/main/scripts/eval_asr_large.py
- Command line
-
hf download hf://oProfM/LuaNovaV1/scripts/eval_asr_large.py
-
curl -L -o eval_asr_large.py https://huggingface.co/oProfM/LuaNovaV1/resolve/main/scripts/eval_asr_large.py
2.52 kB
| """Re-score WER/CER of Lua Nova V1 eval WAVs with faster-whisper large-v3 (same normalization as tts-eval). | |
| Run with experiments/tts-eval/.venv python after sourcing tts-eval/scripts/env.ps1. | |
| Writes eval/scores_asr_large.json and merges `wer_large`/`cer_large` into eval/scores.json summaries. | |
| """ | |
| 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 faster_whisper import WhisperModel # noqa: E402 | |
| from tts_eval.env_setup import configure_env, load_audio_dual_rate # noqa: E402 | |
| from tts_eval.text_ptbr import cer, wer # noqa: E402 | |
| EXP = Path(__file__).resolve().parents[1] | |
| EVAL = EXP / "eval" | |
| MODEL = "large-v3" | |
| def main() -> None: | |
| configure_env() | |
| model = WhisperModel(MODEL, device="cuda", compute_type="float16") | |
| scores = json.loads((EVAL / "scores.json").read_text(encoding="utf-8")) | |
| import importlib.util | |
| spec = importlib.util.spec_from_file_location("es", Path(__file__).with_name("eval_score.py")) | |
| es = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(es) | |
| txt = es.texts() | |
| out: dict = {"asr_model": f"faster-whisper {MODEL} (fp16, beam 5, lang=pt, vad)"} | |
| for key in scores: | |
| system, split = key.split("/") | |
| rows = [] | |
| for wid, text in txt[split].items(): | |
| p = EVAL / system / split / f"{wid}.wav" | |
| if not p.exists(): | |
| continue | |
| _, _, w16 = load_audio_dual_rate(p) | |
| segs, _ = model.transcribe(w16, language="pt", vad_filter=True, beam_size=5, | |
| condition_on_previous_text=False, temperature=0.0) | |
| hyp = " ".join(s.text.strip() for s in segs).strip() | |
| rows.append({"id": wid, "asr_text": hyp, "wer": round(wer(text, hyp), 4), "cer": round(cer(text, hyp), 4)}) | |
| summ = {"wer": round(float(np.mean([r["wer"] for r in rows])), 4), | |
| "cer": round(float(np.mean([r["cer"] for r in rows])), 4), "n": len(rows)} | |
| out[key] = {"summary": summ, "items": rows} | |
| scores[key]["summary"]["wer_large"] = summ["wer"] | |
| scores[key]["summary"]["cer_large"] = summ["cer"] | |
| print(key, summ, flush=True) | |
| (EVAL / "scores_asr_large.json").write_text(json.dumps(out, indent=2, ensure_ascii=False), encoding="utf-8") | |
| (EVAL / "scores.json").write_text(json.dumps(scores, indent=2, ensure_ascii=False), encoding="utf-8") | |
| if __name__ == "__main__": | |
| main() | |