Dynamic Accent Pro v1.1 (experimental prompt-controlled Nigerian TTS); Flash-DPO default, Pro via --instruct
582aab9 verified Download pause_text.py from Modularcomputing/dynamic-accent-pro-v1.1: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/Modularcomputing/dynamic-accent-pro-v1.1/resolve/main/pause_text.py
- Command line
-
hf download hf://Modularcomputing/dynamic-accent-pro-v1.1/pause_text.py
-
curl -L -o pause_text.py https://huggingface.co/Modularcomputing/dynamic-accent-pro-v1.1/resolve/main/pause_text.py
1.61 kB
| """Text-side pause control (pipeline step): 'many pauses' -> insert the model's trained [pause] tag at commas and | |
| every ~5 words inside long phrases; 'few pauses' -> drop commas/semicolons and [pause] tags inside sentences.""" | |
| import re | |
| TAGRE = re.compile(r"(<\w+>)(.*?)(</\w+>)", re.S) | |
| def _many(s, every=5): | |
| out = [] | |
| for sent in re.split(r"(?<=[.!?])\s+", s.strip()): | |
| parts = re.split(r"(,|;|:)", sent) | |
| buf = [] | |
| for p in parts: | |
| if p in (",", ";", ":"): | |
| buf.append(p + " [pause]"); continue | |
| w = p.split(); chunk = [] | |
| for i, x in enumerate(w): | |
| chunk.append(x) | |
| if (i + 1) % every == 0 and i + 1 < len(w) - 1: | |
| chunk.append("[pause]") | |
| buf.append(" ".join(chunk)) | |
| out.append(" ".join(b for b in buf if b).replace(" ,", ",").replace(" ;", ";")) | |
| return " [pause] ".join(out) if len(out) > 1 else out[0] | |
| def _few(s): | |
| s = s.replace("[pause]", " ").replace("[breath]", " ") | |
| s = re.sub(r"\s*[,;:]\s*", " ", s) | |
| return " ".join(s.split()) | |
| def apply(text, mode): | |
| f = _many if mode == "many" else _few if mode == "few" else None | |
| if f is None: | |
| return text | |
| if TAGRE.search(text): | |
| return TAGRE.sub(lambda m: m.group(1) + f(m.group(2)) + m.group(3), text) | |
| return f(text) | |
| if __name__ == "__main__": | |
| t = "<ibo>Ndewo nụ, ụmụnna m.</ibo> <eng>Tonight we will talk about the new market road and the school fees,</eng> <ibo>ma ọ bụrụ na ego ezughị.</ibo>" | |
| print(apply(t, "many")); print(apply(t, "few")) | |