Speak every sentence when ChatTTS streams multi-sentence text #781
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 638 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #781"
general
weight: 0.35
jackboyla
With streaming on (the default), the ChatTTS backend speaks only the first part of each input that ChatTTS splits into sentences (at
.and。, or at newlines). The rest is dropped.Problem
Since ChatTTS 0.2.2,
Chat.infer()splits a string into sentences by default (split_text=True: after。or., or at newlines) and synthesizes them as one batch. In stream mode each chunk is then a(sentences, samples)array with one row per sentence, all advancing together. ChatTTS's own stream example walks those rows one sentence at a time.ChatTTSHandlerplaysgen[0]of each chunk, which is row 0: the first sentence. The other rows are dropped, and while the longer sentences are still being generated, row 0 is padding, which plays as silence.The defaults make this the usual case:
--chat_tts_streamdefaults to true.pip install "speech-to-speech[chattts]"resolves to ChatTTS 0.2.5 today.--stream_batch_sentences 3), joined with spaces.Non-stream mode is not affected: there
infer()joins the rows itself.Reproduction
Reproduced with ChatTTS 0.2.5's own
Chat.infer()and_infer(): theclass Chatfrom the PyPI sdist, executed on its own, with the model calls replaced by fakes that speak each sentence as its own tone (512 samples per audio token). Input:Sure, I can help with that. The station is two blocks north. Turn left at the bakery., which is 5.31 s of fake speech.Chunk shapes from
infer(text, stream=True):The same
ChatbehindChatTTSHandler.process()(16 kHz output; share of the spectrum at each sentence's tone):| | audio out | sentence 1 / 2 / 3 |
|---|---|---|
|
main, stream | 2.08 s | 0.996 / 0.000 / 0.000 ||
main, non-stream | 5.31 s | 0.325 / 0.385 / 0.288 || this PR, stream | 5.44 s | 0.324 / 0.383 / 0.288 |
The extra 0.13 s in stream mode is the handler's existing zero padding of each chunk's last 512-sample block. The ChatTTS 0.2.2 code gives the same numbers. No weights were loaded, so this checks shapes and routing, not the voice.
Change
When streaming, call
infer(..., split_text=False). ChatTTS then synthesizes the input as one row, so each chunk continues the whole utterance. That is what ChatTTS 0.2.1 returned for any string (it has nosplit_text), and what the stream loop is written for. As in 0.2.1, themax_new_tokenbudget (2048 tokens by default, about 43 s of speech) then covers the whole input instead of each sentence; the default 3-sentence batches stay far below it.Walking the rows the way ChatTTS's example does would also work, but it needs buffering and a silence check to tell when a sentence has ended. A single row keeps the stream loop as it is.
Non-stream keeps ChatTTS's default, so that path does not change.
On ChatTTS 0.2.1 the new keyword raises
TypeError: Chat.infer() got an unexpected keyword argument 'split_text', so thechatttsextra now requiresChatTTS>=0.2.2(released January 2025).Side effect in stream mode: the first time a multi-sentence input arrives with
split_text=True,_infer()synthesizes sentence 1 on its own and stores it as a speaker sample (spk_smp,txt_smp) on the handler's long-livedparams_infer_code; every later synthesis is then prompted with that sample. Withsplit_text=Falsethis never happens in stream mode, so the voice comes fromspk_embalone, as with 0.2.1.Test verification (RED → GREEN)
New
test_streaming_speaks_every_sentence_of_the_inputintests/test_chattts_streaming.py. Its fakeinferstreams like ChatTTS 0.2.2 and later: unlesssplit_text=False, it splits after.and yields one zero-padded row per sentence, with sentence k at the constant level k/10, and the test checks that each sentence plays in full and in order (not interleaved). Onmain:It passes with the change. The existing ChatTTS fakes already accept
**kwargs.Validation
pytest tests/test_chattts_streaming.py tests/test_chattts_tts_latency.py tests/test_device.py tests/test_handler_logging_hygiene.py tests/openai_realtime/test_turn_latency.py: 78 passed (Windows, Python 3.11)ruff checkandruff format --checkonsrc/andtests/: cleanmypy src/with--platform linux, as in CI: no issues in 155 source files#759 rewrites the line just above this
infer()call, so whichever of the two lands second will need a small merge there.