Download recipe/filter/select_stream.py from KaleComputer/kale-tts-1-tiny: direct link, hf CLI and curl.
- Browser
- Download file 6.55 kB
-
https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/recipe/filter/select_stream.py
- Command line
-
hf download hf://KaleComputer/kale-tts-1-tiny/recipe/filter/select_stream.py
-
curl -L -o select_stream.py https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/recipe/filter/select_stream.py
6.55 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| # Copyright 2026 Kale | |
| """Pick the voice designs that pass, as stream_filter.py's rows land (16 Nov 2026; the screen that admitted the newer release voices). | |
| Pass (on the design's own takes, thresholds in config/stream.json "select"): >= 2 of its test-line takes clean (end token, <= 1 missed | |
| word, no clipping, no creak on any sentence end; whispered-by-design voices exempt from creak), test-line pick clean, >= 1 clean take of | |
| its own line, unclear <= 6 per 100 words, UTMOS: test-line pick >= 3.5 (whisper voices >= 3.0), line pick >= 3.0, both picks inside | |
| the pace window (160-200 wpm). | |
| Distinct (ECAPA centroid of the test-line takes): cosine < 0.80 to each voice already in your model (--refs) and < 0.85 to every voice | |
| selected before it (greedy, best first within what has landed). | |
| python3 -I select_stream.py <group> [--refs design/ref-centroids.json] [--once] | |
| Inputs: <root>/design/stream-<group>.jsonl (+ every other design/stream-*.jsonl: those voices count as already selected only if they are | |
| in design/selected.json); --refs = {"<name>": [ECAPA centroid]} for the voices already in your model (e.g. "cent" of their stream rows). | |
| Outputs: <root>/design/selected.json (one row per selected design), the pick wavs copied to <root>/design/selected/<voice>.wav and | |
| <voice>_line.wav, and a decision log <root>/results/select-<group>.log. Loops until stream_filter.py prints DRIVE-DONE into | |
| <root>/logs/drive-<group>.log (or once with --once). root = env KALE_TTS_ROOT or ".". | |
| Trimmed from the original: publishing to our internal listening page (mp3 at -16 LUFS, page manifest, page-specific archive rule).""" | |
| import argparse | |
| import json | |
| import os | |
| import shutil | |
| import tempfile | |
| import time | |
| from pathlib import Path | |
| import numpy as np | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("group"); ap.add_argument("--refs", default=""); ap.add_argument("--once", action="store_true") | |
| A = ap.parse_args() | |
| H = Path(os.environ.get("KALE_TTS_ROOT", ".")) | |
| G, ONCE = A.group, A.once | |
| SEL = {"clean_takes_min": 2, "unclear_max": 6, "utmos_pick_min": 3.5, "utmos_pick_min_whisper": 3.0, "utmos_line_min": 3.0, | |
| "wpm_lo": 160, "wpm_hi": 200, "max_cos_to_model": 0.80, "max_cos_to_selected": 0.85} | |
| for _p in (os.environ.get("KALE_TTS_STREAM_CONFIG"), Path(__file__).resolve().parent / "config" / "stream.json"): | |
| if _p and Path(_p).is_file(): | |
| SEL.update(json.loads(Path(_p).read_text()).get("select", {})) | |
| break | |
| REF = {k: np.array(v) for k, v in json.loads(Path(A.refs).read_text()).items()} if A.refs else {} | |
| OUT = H / "design/selected" | |
| OUT.mkdir(parents=True, exist_ok=True) | |
| def write(man): | |
| fd, t = tempfile.mkstemp(dir=H / "design", prefix=".selected.", suffix=".json") | |
| with os.fdopen(fd, "w") as fh: json.dump(man, fh, indent=1) | |
| os.replace(t, H / "design/selected.json") | |
| def passed(o): | |
| s, ex = o["scores"], o.get("creak_exempt") | |
| lp = o.get("line_pick") or {} | |
| return (o["clean_takes"] >= SEL["clean_takes_min"] and o["pick"]["clean"] and o["line_clean"] >= 1 and lp.get("clean") and s["unclear"] <= SEL["unclear_max"] | |
| and o["pick"]["utmos"] >= (SEL["utmos_pick_min_whisper"] if ex else SEL["utmos_pick_min"]) and lp.get("utmos", 0) >= SEL["utmos_line_min"] | |
| and SEL["wpm_lo"] <= o["pick"]["wpm_full"] <= SEL["wpm_hi"] and SEL["wpm_lo"] <= lp.get("wpm_full", 0) <= SEL["wpm_hi"]) | |
| (H / "results").mkdir(parents=True, exist_ok=True) | |
| log = open(H / f"results/select-{G}.log", "a") | |
| seen = set() | |
| while True: | |
| sp = H / f"design/stream-{G}.jsonl" | |
| rows = [json.loads(l) for l in sp.read_text().splitlines()] if sp.exists() else [] | |
| man = json.loads((H / "design/selected.json").read_text()) if (H / "design/selected.json").exists() else [] | |
| have = {m["id"] for m in man} | |
| E = {} | |
| for f in H.glob("design/stream-*.jsonl"): # every streamed design (other groups too) | |
| for l in f.read_text().splitlines(): E[json.loads(l)["voice"]] = np.array(json.loads(l)["cent"]) | |
| on_list = [E[i] for i in have if i in E] | |
| new = [r for r in rows if r["voice"] not in seen and r["voice"] not in have] | |
| new.sort(key=lambda o: -(o["scores"]["utmos"] + o["clean_takes"] / max(1, o["takes"]) + 0.3 * (o.get("line_pick") or {}).get("utmos", 0))) | |
| for o in new: | |
| seen.add(o["voice"]) | |
| c = E[o["voice"]] | |
| nc = max(((k, float(c @ REF[k])) for k in REF), key=lambda x: x[1], default=("-", 0.0)) | |
| na = max([float(c @ x) for x in on_list] or [0]) | |
| why = None if passed(o) else "quality" | |
| if not why and nc[1] >= SEL["max_cos_to_model"]: why = f"close to model voice {nc[0]} {nc[1]:.3f}" | |
| if not why and na >= SEL["max_cos_to_selected"]: why = f"close to a selected voice {na:.3f}" | |
| log.write(json.dumps(dict(t=time.strftime("%H:%M"), voice=o["voice"], label=o.get("label"), why=why or "selected", clean=o["clean_takes"], line_clean=o["line_clean"], | |
| scores=o["scores"], pick_utmos=o["pick"]["utmos"], line_utmos=(o.get("line_pick") or {}).get("utmos"))) + "\n"); log.flush() | |
| if why: | |
| continue | |
| for src, f in ((o["raw"], f"{o['voice']}.wav"), (o["raw_line"], f"{o['voice']}_line.wav")): | |
| shutil.copyfile(src, OUT / f) | |
| man.append(dict(id=o["voice"], n=len(man) + 1, label=o.get("label"), gender=o["gender"], age=o.get("age"), accent=o.get("accent"), | |
| wpm=round(o["pick"]["wpm_full"]), target_wpm=o["target_wpm"], file=f"selected/{o['voice']}.wav", line_text=o["line"], | |
| line_file=f"selected/{o['voice']}_line.wav", line_wpm=round(o["line_pick"]["wpm_full"]), description=o["description"], | |
| scores=o["scores"], clean_takes=f"{o['clean_takes']}/{o['takes']}", pick_utmos=o["pick"]["utmos"], line_utmos=o["line_pick"]["utmos"], | |
| nearest_model_voice=dict(voice=nc[0], cos=round(nc[1], 3)), nearest_selected_cos=round(na, 3), | |
| source=f"original Maya-1 audio (designed voice, vLLM bf16), takes {o['pick']['clip']} + {o['line_pick']['clip']}")) | |
| on_list.append(c); have.add(o["voice"]) | |
| write(man) | |
| print(time.strftime("%H:%M"), "selected", o["voice"], o.get("label"), "| list now", len(man), flush=True) | |
| done = "DRIVE-DONE" in (H / f"logs/drive-{G}.log").read_text() if (H / f"logs/drive-{G}.log").exists() else False | |
| if ONCE or (done and not [r for r in rows if r["voice"] not in seen]): | |
| break | |
| time.sleep(20) | |
| print("SELECT-DONE", G, flush=True) | |