Normalize punctuation before German TTS
This commit is contained in:
@@ -290,16 +290,22 @@ def clean_for_speech(text: str) -> str:
|
||||
text = re.sub(r"(?m)^\s{0,3}#{1,6}\s*", "", text)
|
||||
text = re.sub(r"(?m)^\s*[-*+]\s+", "", text)
|
||||
text = text.replace("→", ". ").replace("←", ". ")
|
||||
text = text.replace("–", " - ").replace("—", " - ")
|
||||
if DEFAULT_LANGUAGE == "de":
|
||||
text = normalize_for_german_speech(text)
|
||||
# XTTS occasionally hallucinates syllables when visual punctuation is
|
||||
# submitted literally or isolated at a chunk boundary. Preserve its pause
|
||||
# semantics, but never ask the model to pronounce the glyph itself.
|
||||
text = re.sub(r"(?<=\w)[\-‐‑‒–—−](?=\w)", " ", text)
|
||||
text = re.sub(r"\s+[\-‐‑‒–—−]\s+", ", ", text)
|
||||
text = re.sub(r"\s*[:;]+\s*", ", ", text)
|
||||
text = "".join(
|
||||
char for char in text
|
||||
if unicodedata.category(char) not in {"So", "Cs"}
|
||||
)
|
||||
text = re.sub(r"[ \t]+", " ", text)
|
||||
text = re.sub(r"\s*\n+\s*", ". ", text)
|
||||
text = re.sub(r"([:;])\s*\.", r"\1", text)
|
||||
text = re.sub(r",\s*\.", ".", text)
|
||||
text = re.sub(r"(?:,\s*){2,}", ", ", text)
|
||||
text = re.sub(r"(?:\.\s*){2,}", ". ", text)
|
||||
return text.strip()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user