Skip to content

SMOODEV-2668: Fix browser-voice TTS static (frame alignment + proper resampling)#37

Merged
brentrager merged 1 commit into
mainfrom
SMOODEV-2668-voice-static
Jul 17, 2026
Merged

SMOODEV-2668: Fix browser-voice TTS static (frame alignment + proper resampling)#37
brentrager merged 1 commit into
mainfrom
SMOODEV-2668-voice-static

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

The Chakra Transformation Posture voice pilot plays TTS with heavy static. Spectral analysis of a session recording showed three artifact classes:

  1. Broadband white-noise bursts — TTS frames arrive split at arbitrary byte boundaries; an odd-length frame threw on new Int16Array(chunk) (dropped → gap) and left every subsequent frame decoding one byte off (high/low bytes of adjacent samples paired) until parity restored.
  2. Imaging static above 8 kHz (hard notch at exactly 8 kHz + mirrored speech energy) — forcing AudioContext({sampleRate: 16000}) leaves the 16k→hardware conversion to the browser's output resampler, which images.
  3. Clicks at chunk boundaries — just-in-time chunks scheduled exactly at the playhead.

Solution

  • Carry a dangling byte across frames so decode stays sample-aligned regardless of wire chunking.
  • Run the AudioContext at its native rate and upsample 16 kHz → device rate with a stateful Hann-windowed-sinc streaming interpolator (bit-identical across arbitrary chunk splits; tested).
  • Prime playback 100 ms off the playhead when the queue has drained.

Server-side counterpart (even-byte frame alignment at the source + suggestedNextActions JSON strip) lands in the monorepo under the same ticket.

Verification

  • 176/176 unit tests pass (new: odd-split reassembly, 48k upsampling schedule math, split-vs-whole bit-identity, in-band tone fidelity <1% error).
  • pnpm check green (typecheck + test + build).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tz7j9eqPBBL36CEFZpjoWz

…ate resampling, drain priming

The wire is one continuous 16 kHz linear16 byte stream but frames split at
arbitrary TCP boundaries: an odd-length frame threw on the Int16Array view
(chunk dropped) and left every following frame decoding one byte off — loud
white noise until parity restored. Carry the dangling byte across frames.

Also stop forcing a 16 kHz AudioContext: the browser's context→hardware
resampling mirrored speech energy above 8 kHz (imaging static). Run the
context at its native rate and upsample with a stateful windowed-sinc
interpolator that is seamless across chunk boundaries. Prime playback 100 ms
off the playhead when the queue has drained so just-in-time chunks don't
butt the playhead and click.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tz7j9eqPBBL36CEFZpjoWz
@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 69c781e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smooai/chat-widget Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager
brentrager merged commit dc17f25 into main Jul 17, 2026
1 check passed
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