Files
speech-nano/tinytts_text_cleaning.py
T
2026-06-16 19:32:09 +00:00

29 lines
660 B
Python

from __future__ import annotations
import re
_QUOTE_TRANSLATION = str.maketrans(
{
"\u2018": "'",
"\u2019": "'",
"\u201c": "",
"\u201d": "",
"\u2014": ",",
"\u2013": ",",
";": ",",
":": ",",
"\n": ".",
}
)
def clean_tinytts_text(text: str) -> str:
"""Normalize text into punctuation TinyTTS actually has symbols for."""
text = str(text).translate(_QUOTE_TRANSLATION)
text = text.replace("...", "")
text = re.sub(r"\s+", " ", text).strip()
text = re.sub(r"\s+([,.!?…])", r"\1", text)
text = re.sub(r"([,.!?…]){2,}", r"\1", text)
return text