From a0de0c9e28dcab68e9646144074f0d3cb8485574 Mon Sep 17 00:00:00 2001 From: Kolja Beigel Date: Thu, 23 Nov 2023 12:02:53 +0100 Subject: [PATCH] Fix for sentence end punctuation handling bug --- RealtimeTTS/engines/coqui_engine.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RealtimeTTS/engines/coqui_engine.py b/RealtimeTTS/engines/coqui_engine.py index 3a1ebb1..4536e87 100644 --- a/RealtimeTTS/engines/coqui_engine.py +++ b/RealtimeTTS/engines/coqui_engine.py @@ -316,13 +316,13 @@ def synthesize(self, #text= re.sub("([^\x00-\x7F]|\w)(\.|\。|\?)",r"\1 \2",text) try: - if text[-1] in ["."]: + if len(text) > 2 and text[-1] in ["."]: text = text[:-1] - elif text[-1] in ["!", "?", ","]: + elif len(text) > 2 and text[-1] in ["!", "?", ","]: text = text[:-1] + " " + text[-1] - elif text[-2] in ["."]: + elif len(text) > 3 and text[-2] in ["."]: text = text[:-2] - elif text[-2] in ["!", "?", ","]: + elif len(text) > 3 and text[-2] in ["!", "?", ","]: text = text[:-2] + " " + text[-2] except Exception as e: logging.warning (f"Error fixing sentence end punctuation: {e}, Text: \"{text}\"")