diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2026-09-26 20:21:47 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2026-09-26 20:21:47 -0300 |
| commit | 59355909f2de9236af8168a26c70bcf6caa3b285 (patch) | |
| tree | 686186e2086f81aa22ad25e78eb29fca3cbadc9a /scripts/regen.py | |
| download | 100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.tar.gz 100cia-videos-59355909f2de9236af8168a26c70bcf6caa3b285.zip | |
Import video pipeline as it was
Diffstat (limited to 'scripts/regen.py')
| -rw-r--r-- | scripts/regen.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/regen.py b/scripts/regen.py new file mode 100644 index 0000000..7ff69a8 --- /dev/null +++ b/scripts/regen.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +"""Regenera segmentos puntuales probando varias semillas y quedandose con la mejor.""" +import json, os, subprocess, sys, shutil +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from narration import SCRIPTS +from gen_audio import synth_seguro, transcribe, dur, ROOT +from verify import norm +from difflib import SequenceMatcher + +TRIES = 5 + + +def main(name, idxs): + outdir = os.path.join(ROOT, "audio", name) + work = os.path.join(ROOT, "tmp", name + "_rg") + os.makedirs(work, exist_ok=True) + data = json.load(open(os.path.join(outdir, "segments.json"), encoding="utf-8")) + segs = SCRIPTS[name]["segments"] + + for i in idxs: + text = segs[i][0] + cands = [] + for k in range(TRIES): + c = os.path.join(work, f"{i:02d}_{k}.wav") + synth_seguro(text, c, 4242 + 977 * k, f"[{name}] {i:02d}") + cands.append(c) + tr = transcribe(cands, work) + scored = sorted(((SequenceMatcher(None, norm(text, False), + norm(tr[c], False)).ratio(), c) for c in cands), + reverse=True) + for r, c in scored: + print(f" {i:02d} seed{cands.index(c)} r={r:.2f} {dur(c):.2f}s | {tr[c][:70]}") + best_r, best = scored[0] + shutil.copy(best, os.path.join(outdir, f"{i:02d}.wav")) + data["segments"][i].update(tts=text, sub=segs[i][1], + dur=round(dur(best), 3), score=round(best_r, 3)) + print(f" -> {i:02d} elegido r={best_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}] actualizado, audio={data['total_audio']}s") + + +if __name__ == "__main__": + main(sys.argv[1], [int(x) for x in sys.argv[2:]]) |