Skip to content

perf(desktop): stream Pocket TTS decoder chunks - #3257

Open
johnmatthewtennant wants to merge 6 commits into
mainfrom
jtennant/pocket-tts-streaming
Open

perf(desktop): stream Pocket TTS decoder chunks#3257
johnmatthewtennant wants to merge 6 commits into
mainfrom
jtennant/pocket-tts-streaming

Conversation

@johnmatthewtennant

@johnmatthewtennant johnmatthewtennant commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Context

Pocket TTS waits for a complete synthesis unit before queuing audio even though its decoder produces usable PCM blocks during generation. Long agent replies therefore begin later than necessary.

The callback is cumulative and may repeat a length between internal model chunks, so playback must queue only each new suffix and reject decreasing lengths.

Summary

Queue Pocket TTS decoder output as it arrives while the resident engine continues synthesizing. Playback remains ordered and cancellable, including during silent decoder gaps.

Changes

  • Expose callback-driven Pocket synthesis while preserving the buffered API.
  • Convert cumulative PCM into ordered suffixes and fail closed on callback contract violations.
  • Keep only the final tail needed for the utterance fade, then queue audio while synthesis continues.
  • Keep the first sentence as a playback boundary while handling 50-token model splits internally, without extra playback pauses.
  • Keep synthesis activity armed through final queueing so PTT, barge-in, preview completion, voice changes, and shutdown observe the correct state.
  • Cover ordering, repeated callback lengths, cancellation, quiet onsets, underrun restart, queue errors, silent-gap microphone gating, and playback grouping.

Related issue

None found.

Testing

Manual validation in the combined daily-driver build confirmed that long replies begin playing before synthesis completes, decoder boundaries have no repeated or omitted audio, PTT and barge-in cancel during active playback and silent decoder gaps, and voice Preview completes.

For the same long input, warm Pocket TTS produced its first usable callback at 1020.0 ms and completed synthesis at 3220.9 ms. The output was 16.640 seconds of audio at 0.194 RTF. Buffered and streaming assembly produced byte-identical PCM, and callback cancellation returned in 0.0 ms.

Screenshots

Not applicable. This changes the native audio pipeline and has no visual UI change.

Reviewer-reproducible examples

From a fresh checkout with the Pocket voice model installed:

. ./bin/activate-hermit
just dev
  1. In Voice settings, enable Agent text to speech and select a Pocket voice.
  2. Join an agent huddle and request a long, multi-sentence response.
  3. Confirm speech begins before the response finishes synthesizing and remains continuous at sentence and model-token boundaries.
  4. Hold PTT or speak once during audible playback and once during a silent decoder gap. Confirm the remaining speech stops immediately and microphone input continues.
  5. Run Voice Preview and confirm it plays to completion.

Observed on the PR build: speech began during synthesis, no repeated, omitted, gapped, clicked, or clipped audio was heard, both cancellation paths stopped the remaining speech, and Preview completed.

@johnmatthewtennant
johnmatthewtennant force-pushed the jtennant/pocket-tts-settings-v1 branch from 4891a92 to c118f5a Compare July 28, 2026 04:48
@johnmatthewtennant
johnmatthewtennant force-pushed the jtennant/pocket-tts-streaming branch from 7f7eb66 to 93602d9 Compare July 28, 2026 05:36
@johnmatthewtennant
johnmatthewtennant force-pushed the jtennant/pocket-tts-settings-v1 branch 3 times, most recently from ea833b1 to 6186fc2 Compare July 29, 2026 16:37
@johnmatthewtennant
johnmatthewtennant force-pushed the jtennant/pocket-tts-streaming branch from 93602d9 to 881ce50 Compare July 29, 2026 17:02
@johnmatthewtennant
johnmatthewtennant marked this pull request as ready for review July 29, 2026 23:34
@johnmatthewtennant
johnmatthewtennant requested a review from a team as a code owner July 29, 2026 23:34
@johnmatthewtennant
johnmatthewtennant marked this pull request as draft July 30, 2026 01:59
@johnmatthewtennant
johnmatthewtennant marked this pull request as ready for review July 30, 2026 02:49
tlongwell-block pushed a commit that referenced this pull request Jul 31, 2026
Co-authored-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@buzz.block.builderlab.xyz>
Signed-off-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@buzz.block.builderlab.xyz>
tlongwell-block added a commit that referenced this pull request Jul 31, 2026
Advances this PR's base from 881ce50 to the pushed #3257 head
254eed8. Clean auto-merge, no manual
resolution: three files auto-merged (crates/buzz-voice/src/pocket.rs,
desktop/src-tauri/Cargo.toml, desktop/src-tauri/Cargo.lock) with zero
conflicts and zero index stage entries.

Resulting tree 4a821be matches the
expectation registered independently before this merge existed.

The O(n^3) segmentation fix on 15667de survives byte-identically:
crates/buzz-voice/src/pocket_april.rs is 37ef88e in both this tree and
the pre-merge head, and the base never touched that file.

Derived with rerere disabled so no cached resolution could be replayed.

Co-authored-by: Tyler Longwell <tlongwell@squareup.com>
Signed-off-by: Tyler Longwell <tlongwell@squareup.com>
Base automatically changed from jtennant/pocket-tts-settings-v1 to jt/buzz-voice-refactor July 31, 2026 11:07
johnmatthewtennant and others added 2 commits July 31, 2026 12:56
Signed-off-by: John Tennant <jtennant@squareup.com>
## Context

Pocket TTS decoder streaming begins playback while each model-valid
chunk is still being decoded. Segmentation should preserve a fast
first-sentence boundary, enforce the model's exact 50-token safety
limit, and use natural prosody boundaries for oversized sentences and
the remainder.

## Summary

Move Pocket TTS segmentation into the shared tokenizer-aware layer. A
fitting first sentence stays separate for low time-to-first-audio.
Oversized sentences use clause, word, then UTF-8 scalar fallback, while
later sentences pack into the largest natural unit of at most 50
prepared model tokens. Returned chunks are contiguous and reconstruct
the prepared prompt exactly.

## Changes

- Replace the shared word-only splitter with distinct playback and
model-safety policies using actual SentencePiece counts.
- Keep a fitting first sentence as the initial playback unit, then pack
later sentences into the largest natural model-valid units.
- Split oversized sentences at clause, word, then UTF-8 scalar
boundaries.
- Preserve punctuation, whitespace, Unicode, text order, and exact
reconstruction across chunks.
- Remove the Desktop 200-character splitter while preserving its
low-latency first-sentence behavior in the shared layer.
- Route Desktop playback directly through the shared splitter without
changing streaming, cancellation, queue, fade, or voice-switch behavior.
- Remove the unused Desktop sentence splitter and its tests.

## Related issue

None found.

## Testing

Parent versus child medians after one warmup and three measured runs:

| Response | Parent TTFA | Child TTFA | Delta | Parent RTF | Child RTF |
| --- | ---: | ---: | ---: | ---: | ---: |
| Short | 335.328 ms | 317.890 ms | -17.439 ms | 0.231865 | 0.220702 |
| Medium | 472.118 ms | 383.934 ms | -88.184 ms | 0.214413 | 0.188397 |
| Long | 922.557 ms | 682.583 ms | -239.974 ms | 0.186114 | 0.185482 |

In this measured run, preserving the first-sentence boundary improved
median TTFA for all three response lengths while the natural remainder
policy kept median RTF lower for all three.

Cancellation after callback 2 returned `Interrupted` in 0.0195 ms.
Boundary cancellation prevented chunk 2 from starting. Every final
callback matched returned PCM byte-for-byte, callback lengths were
monotonic, splitting was deterministic, and text reconstruction was
exact.

## Reviewer-reproducible examples

Run model-independent boundary properties:

```sh
cargo test --manifest-path crates/buzz-voice/Cargo.toml --lib natural_split
cargo test --manifest-path crates/buzz-voice/Cargo.toml --lib oversized
```

Run the cached-model cases:

```sh
BUZZ_POCKET_TEST_MODEL_DIR=/path/to/april-int8-bundle \
  cargo test --manifest-path crates/buzz-voice/Cargo.toml --lib -- --ignored --nocapture
```

The 90-token Gary sentence reconstructs exactly as three natural chunks
of 32, 42, and 15 prepared tokens.

Automated transcription found complete expected endings in all six
clips, with no clipping, late onset, or meaningful DC offset. Manual
listening in the combined daily-driver build also completed
successfully.

## Screenshots

N/A, nonvisual audio behavior.

---------

Signed-off-by: John Tennant <jtennant@squareup.com>
Signed-off-by: Tyler Longwell <tlongwell@squareup.com>
Co-authored-by: npub1jmc9dt2lyvzu3h0kxlwxt5zg4fxp9476awyxw6gwxn72g6cw7exqs64whm <96f056ad5f2305c8ddf637dc65d048aa4c12d7daeb8867690e34fca46b0ef64c@buzz.block.builderlab.xyz>
Co-authored-by: Tyler Longwell <tlongwell@squareup.com>
@johnmatthewtennant
johnmatthewtennant force-pushed the jtennant/pocket-tts-streaming branch from 4d18f5b to efbc63d Compare July 31, 2026 17:03
@johnmatthewtennant
johnmatthewtennant changed the base branch from jt/buzz-voice-refactor to main July 31, 2026 17:03
Signed-off-by: John Tennant <jtennant@squareup.com>
Signed-off-by: John Tennant <jtennant@squareup.com>
Signed-off-by: John Tennant <jtennant@squareup.com>
Signed-off-by: John Tennant <jtennant@squareup.com>
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