aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/repick.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/repick.py
download100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.tar.gz
100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.zip
Import video pipeline as it was
Diffstat (limited to 'scripts/repick.py')
-rw-r--r--scripts/repick.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/repick.py b/scripts/repick.py
new file mode 100644
index 0000000..5f75bcf
--- /dev/null
+++ b/scripts/repick.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+"""Vuelve a elegir el mejor candidato ya sintetizado, comparando numeros en palabras."""
+import json, os, shutil, sys, wave
+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 verify import norm
+
+
+def dur(p):
+ with wave.open(p) as w:
+ return w.getnframes() / w.getframerate()
+
+
+def main(name, idxs):
+ work = os.path.join(ROOT, "tmp", name + "_rg")
+ outdir = os.path.join(ROOT, "audio", name)
+ data = json.load(open(os.path.join(outdir, "segments.json"), encoding="utf-8"))
+ segs = SCRIPTS[name]["segments"]
+ for i in idxs:
+ cands = []
+ for k in range(10):
+ w = os.path.join(work, f"{i:02d}_{k}.wav")
+ t = os.path.join(work, f"{i:02d}_{k}.txt")
+ if os.path.exists(w) and os.path.exists(t):
+ got = open(t, encoding="utf-8").read().strip()
+ r = SequenceMatcher(None, norm(segs[i][0]), norm(got)).ratio()
+ cands.append((r, k, w, got))
+ if not cands:
+ print(f" {i:02d} sin candidatos"); continue
+ cands.sort(reverse=True)
+ for r, k, w, got in cands:
+ print(f" {i:02d} seed{k} r={r:.2f} {dur(w):.2f}s | {got[:72]}")
+ r, k, w, got = cands[0]
+ shutil.copy(w, os.path.join(outdir, f"{i:02d}.wav"))
+ data["segments"][i].update(tts=segs[i][0], sub=segs[i][1],
+ dur=round(dur(w), 3), score=round(r, 3))
+ print(f" -> {i:02d} elegido seed{k} r={r:.2f}\n")
+ data["total_audio"] = round(sum(s["dur"] for s in data["segments"]), 2)
+ json.dump(data, open(os.path.join(outdir, "segments.json"), "w", encoding="utf-8"),
+ ensure_ascii=False, indent=2)
+ print(f"[{name}] audio={data['total_audio']}s")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1], [int(x) for x in sys.argv[2:]])