← Back to Pull requests

Speak every sentence when ChatTTS streams multi-sentence text #781

Closed
unknown closed this pull request without merging on Nov 12, 2026 13:39 UTC
View on GitHub
unknown unknown commented on Nov 01, 2026 20:26 UTC
Author

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.

ChatTTSHandler plays gen[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_stream defaults to true.

  • pip install "speech-to-speech[chattts]" resolves to ChatTTS 0.2.5 today.

  • Both the local and the OpenAI-compatible LLM handlers send TTS three sentences at a time (--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(): the class Chat from 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):

    split_text=True (default): (3, 12000), (3, 12000), (3, 25152)
    split_text=False:          (1, 12000) x 9, then (1, 19488)
    

    The same Chat behind ChatTTSHandler.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 no split_text), and what the stream loop is written for. As in 0.2.1, the max_new_token budget (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 the chattts extra now requires ChatTTS>=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-lived params_infer_code; every later synthesis is then prompted with that sample. With split_text=False this never happens in stream mode, so the voice comes from spk_emb alone, as with 0.2.1.

    Test verification (RED → GREEN)

    New test_streaming_speaks_every_sentence_of_the_input in tests/test_chattts_streaming.py. Its fake infer streams like ChatTTS 0.2.2 and later: unless split_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). On main:

    >       assert runs == [(1, 4000), (2, 8000), (3, 12000)]
    E       assert [(1, 4000)] == [(1, 4000), (...), (3, 12000)]
    

    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 check and ruff format --check on src/ and tests/: clean

  • mypy 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.

    Diff: 638 lines (+478 / -160) across 7 files Reviewer: jackboyla Review duration: 15432m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%