From 1d73d5faccec487b072ca17926fa9f7b157395ee Mon Sep 17 00:00:00 2001 From: EloquentBrush0x <283442588+EloquentBrush0x@users.noreply.github.com> Date: Wed, 20 May 2026 21:36:32 +0300 Subject: [PATCH] fix(tts): prevent double [pause] in xAI auto speech tags for multi-paragraph text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _apply_xai_auto_speech_tags runs two independent transformations: 1. paragraph breaks (\n\n) → " [pause] " 2. first-sentence boundary → " [pause] " Both fired unconditionally, so multi-paragraph input produced "Hello world. [pause] [pause] Second paragraph." — an unnatural double pause in the TTS audio. Guard the first-sentence substitution with _XAI_SPEECH_TAG_RE.search(clean): if the paragraph pass already inserted a [pause] tag, skip the first-sentence pass. Single-paragraph behavior is unchanged. --- tools/tts_tool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/tts_tool.py b/tools/tts_tool.py index 0c0c7bd203c..69dea790dee 100644 --- a/tools/tts_tool.py +++ b/tools/tts_tool.py @@ -1078,7 +1078,8 @@ def _apply_xai_auto_speech_tags(text: str) -> str: clean = re.sub(r"\n\s*\n+", " [pause] ", clean) clean = re.sub(r"\s*\n\s*", " ", clean) - clean = _XAI_FIRST_SENTENCE_RE.sub(r"\1 [pause] ", clean, count=1) + if not _XAI_SPEECH_TAG_RE.search(clean): + clean = _XAI_FIRST_SENTENCE_RE.sub(r"\1 [pause] ", clean, count=1) clean = re.sub(r"\s{2,}", " ", clean).strip() return clean