kale-tts-1-tiny / recipe /teacher /make_rows.py
NERDDISCO's picture
kale-tts-1
f21d6eb
Raw History Blame Contribute Delete
2.16 kB
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 Kale
"""teacher rows for teacher.py::lists_entry (glue, adapted from our build drivers): one row per kept take of each teacher voice,
{path (on the data volume, mounted at /renders), ids (Kokoro ids of the take's text from frontend/), spk (voice index in
config/teacher.json teacher_voices), split, clip, seconds}.
usage: python3 make_rows.py <kept dir> <ids map.json> [out=work/teacher-rows.jsonl]
kept dir : the filter step's kept lists, one <voice> file per voice (name pattern = config/packs.json kept_file), rows with
clip, text, path (relative to the data volume), seconds and optionally split ("train" / "val" / "validation")
ids map : {text: [Kokoro ids]} made with the release front end (frontend/, CMUdict + overrides + g2p -> Kokoro ids; no espeak)
Rows without a split field: every <val_every>-th take of a voice goes to val (config/teacher.json)."""
import json
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
C = {k: v for k, v in json.loads((HERE / "config/teacher.json").read_text()).items() if not k.startswith("_")}
P = {k: v for k, v in json.loads((HERE / "config/packs.json").read_text()).items() if not k.startswith("_")}
kept, idmap = Path(sys.argv[1]), json.loads(Path(sys.argv[2]).read_text())
out = Path(sys.argv[3] if len(sys.argv) > 3 else "work/teacher-rows.jsonl")
rows, missing = [], 0
for spk, v in enumerate(C["teacher_voices"]):
for k, r in enumerate(json.loads(l) for l in (kept / P["kept_file"].format(voice=v)).read_text().splitlines() if l.strip()):
if r["text"] not in idmap:
missing += 1
continue
split = {"validation": "val"}.get(r.get("split"), r.get("split")) or ("val" if k % C["val_every"] == 0 else "train")
rows.append(dict(path=f"/renders/{r['path']}", ids=idmap[r["text"]], spk=spk, split=split, clip=r["clip"], seconds=r["seconds"]))
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text("".join(json.dumps(r) + "\n" for r in rows))
print("rows", len(rows), "val", sum(r["split"] == "val" for r in rows), "texts without ids", missing, "->", out)