fix(tts): prevent double [pause] in xAI auto speech tags for multi-paragraph text

_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.
This commit is contained in:
EloquentBrush0x 2026-05-20 21:36:32 +03:00 committed by Teknium
parent b62af47da8
commit 1d73d5facc

View file

@ -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