aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/verify.py
diff options
context:
space:
mode:
authorElvis Claros Castro <elvis@claros.ar>2026-09-26 20:21:47 -0300
committerElvis Claros Castro <elvis@claros.ar>2026-09-26 20:21:47 -0300
commit59355909f2de9236af8168a26c70bcf6caa3b285 (patch)
tree686186e2086f81aa22ad25e78eb29fca3cbadc9a /scripts/verify.py
download100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.tar.gz
100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.zip
Import video pipeline as it was
Diffstat (limited to 'scripts/verify.py')
-rw-r--r--scripts/verify.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/verify.py b/scripts/verify.py
new file mode 100644
index 0000000..b35eb44
--- /dev/null
+++ b/scripts/verify.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+"""Transcribe los WAV finales y compara ignorando la forma de escribir numeros."""
+import json, os, re, subprocess, sys, unicodedata
+from difflib import SequenceMatcher
+
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+sys.path.insert(0, os.path.join(ROOT, "scripts"))
+from narration import SCRIPTS
+from numspell import expand
+
+NUM = set("""cero uno una dos tres cuatro cinco seis siete ocho nueve diez once doce trece
+catorce quince dieciseis diecisiete dieciocho diecinueve veinte veintiuno veintidos veintitres
+treinta cuarenta cincuenta sesenta setenta ochenta noventa cien ciento doscientos trescientos
+cuatrocientos quinientos mil millon millones coma periodico por ciento y tercio tercios
+primero segundo""".split())
+
+
+def norm(s, drop_numbers=False):
+ s = expand(s)
+ s = unicodedata.normalize("NFD", s.lower())
+ s = "".join(c for c in s if unicodedata.category(c) != "Mn")
+ s = re.sub(r"[^a-z0-9ñ ]+", " ", s)
+ toks = s.split()
+ if drop_numbers:
+ toks = [t for t in toks if not t.isdigit() and t not in NUM]
+ return " ".join(toks)
+
+
+def main(names):
+ for name in names:
+ d = json.load(open(os.path.join(ROOT, "audio", name, "segments.json")))
+ wavs = [s["wav"] for s in d["segments"]]
+ work = os.path.join(ROOT, "tmp", name + "_v")
+ os.makedirs(work, exist_ok=True)
+ subprocess.run(["conda", "run", "-n", "stt", "--no-capture-output",
+ "whisper-ctranslate2", "--language", "es", "--model", "small",
+ "--output_dir", work, "--output_format", "txt", *wavs],
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
+ print(f"\n=== {name} ===")
+ bad = []
+ for s in d["segments"]:
+ t = os.path.join(work, os.path.splitext(os.path.basename(s["wav"]))[0] + ".txt")
+ got = open(t, encoding="utf-8").read().strip() if os.path.exists(t) else ""
+ r = SequenceMatcher(None, norm(s["tts"]), norm(got)).ratio()
+ flag = "OK " if r >= 0.88 else "REV"
+ if r < 0.88:
+ bad.append(s["i"])
+ print(f" {s['i']:02d} {flag} {r:.2f} | {got}")
+ print(f" -> revisar: {bad}")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:] or list(SCRIPTS))