"""British voices take the en-gb front end in Python too (as js/kale-tts.mjs and the space): every voice whose voices.json accent is "en-gb" (Amy d03, Jack d13) is read through the British front end, the others through en-us; sizes such as 45.7M are words in both. usage: python test_accents.py [model dir ...] (default: every models/kale-tts-1-* the package finds, else the folder above it) pip install onnxruntime numpy quickjs""" import json, sys from pathlib import Path HERE = Path(__file__).resolve().parent; sys.path.insert(0, str(HERE)) from kale_tts import KaleTTS, QuickJSFrontEnd, _near dirs = [Path(a) for a in sys.argv[1:]] or sorted(p for p in _near("models").glob("kale-tts-1-*") if (p / "voices.json").exists()) \ or [HERE.parent] # a model repo: the model sits at the repo root fe = QuickJSFrontEnd(); bad = []; out = {"accents": sorted(fe.accents), "models": {}} if "en-gb" not in fe.accents: bad.append("no en-gb front end loaded (frontend/words/en-gb missing?)") us, gb = fe("The car is 45.7M times faster.", "en-us")[0], fe("The car is 45.7M times faster.", "en-gb")[0] if "fˈɑːstə" not in gb["ipa"] or "fˈæstɚ" not in us["ipa"]: bad.append(f"accent sounds: us {us['ipa']} / gb {gb['ipa']}") for s in (us, gb): if "forty five point seven million" not in s["text"]: bad.append(f"45.7M said as: {s['text']}") class Spy(QuickJSFrontEnd): """the front end, remembering which accent each call asked for (a QuickJSFrontEnd, so the tiny's Ettin text side runs too)""" def __init__(self, f): self.f, self.calls = f, [] def __call__(self, text, accent="en-us"): self.calls.append(accent); return self.f(text, accent) def init_ettin(self, tokenizer_json): return self.f.init_ettin(tokenizer_json) def ipa_words(self, text, accent="en-us"): self.calls.append(accent); return self.f.ipa_words(text, accent) def ettin(self, *a): return self.f.ettin(*a) for d in dirs: spy = Spy(fe); tts = KaleTTS(d, threads=2, frontend=spy); rows = [] for v in tts.list_voices(): spy.calls.clear() a = tts.speak("The car is 45.7M times faster.", voice=v["id"]) want = "en-gb" if v["accent"] == "en-gb" else "en-us" ok = bool(spy.calls) and set(spy.calls) == {want} and len(a) > 2400 rows.append(dict(voice=v["name"], accent=v["accent"], front_end=sorted(set(spy.calls)), seconds=round(len(a) / 24000, 2), ok=ok)) if not ok: bad.append(f"{d.name} {v['name']}: accent {v['accent']}, front end asked {spy.calls}, {len(a)} samples") gbv = [r["voice"] for r in rows if r["accent"] == "en-gb"] if not {"Amy", "Jack"} <= set(gbv): bad.append(f"{d.name}: en-gb voices are {gbv}, want Amy and Jack among them") out["models"][d.name] = rows print(json.dumps(out, ensure_ascii=False, indent=1)); print("FAIL\n" + "\n".join(bad) if bad else "PASS"); sys.exit(1 if bad else 0)