Skip to content

fix(tts): pick earliest split for the first sentence, latest for the rest#3232

Draft
bradjshannon wants to merge 2 commits into
xinnan-tech:mainfrom
IAI-Smart:fix/tts-first-sentence-latency
Draft

fix(tts): pick earliest split for the first sentence, latest for the rest#3232
bradjshannon wants to merge 2 commits into
xinnan-tech:mainfrom
IAI-Smart:fix/tts-first-sentence-latency

Conversation

@bradjshannon

Copy link
Copy Markdown

Problem

In tts/base.py, _get_segment_text used rfind for every sentence and kept the smallest of the last-occurrence positions across the punctuation set — an inconsistent heuristic for choosing a split point.

Fix

Differentiate by position in the reply:

  • First sentence: take the earliest punctuation boundary (find) so the first audio segment is produced as soon as possible — lower time-to-first-audio.
  • Subsequent sentences: take the latest boundary (rfind) so segments are as large as possible — fewer TTS calls and smoother playback.

The tts_stop_request flush branch is unchanged.

Tests

test/test_tts_segment_split.py — asserts the first sentence splits at the earliest boundary and later sentences at the latest (pinned via processed_chars), plus the no-boundary case.

Risk

Low — a correctness/latency improvement. The first-sentence-vs-rest trade-off (latency vs chunk size) is the one tuning dimension; happy to adjust if maintainers prefer different behavior.

…rest

_get_segment_text used rfind for every sentence and kept the smallest of the
last-occurrence positions across the punctuation set, an inconsistent
heuristic. Differentiate by position in the reply:

- First sentence: take the earliest punctuation boundary (find) so the first
  audio segment is produced as soon as possible — lower time-to-first-audio.
- Subsequent sentences: take the latest boundary (rfind) so segments are as
  large as possible — fewer TTS calls and smoother playback.

The tts_stop_request flush branch is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant