Skip to content

feat(speech): redraw whole speech replies that jump to a high register - #1162

Closed
plotarmordev wants to merge 5 commits into
ashhart:mainfrom
plotarmordev:feat/register-guard
Closed

plotarmordev wants to merge 5 commits into
ashhart:mainfrom
plotarmordev:feat/register-guard

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

Stacked on the silence-redraws PR (#1160); review the diff against its tip 49ea53bd.

Adds an opt-in register guard, serve --register-redraw-st ST --register-redraw-high PERCENT --register-high-hz HZ, to whole Drama speech replies. A take trips when a phrase after the first opens ST semitones or more above the median opening of the other phrases, with PERCENT or more of its voiced frames above HZ. A tripped take is drawn once more, and the take with the smaller jump is sent.

  • Flags: there are no defaults, and the three flags are given together or not at all. ST is finite and above 0, PERCENT is above 0 and at most 100, and HZ is 75 to 600. A partial set or an out-of-range value is a usage error. Text models refuse the set at startup. Without the flags, no take is measured and replies are unchanged. --silence-redraw-budget-s is accepted with the register guard alone.
  • Measure: CPU pitch tracking on the finished take, read every 10 ms by normalized cross-correlation on audio averaged down to 8 to 16 kHz. It uses Praat's published To Pitch (ac) parameter defaults: 75 to 600 Hz, voicing 0.45, silence 0.03 of the peak and octave cost 0.01.
    • Unvoiced runs of 0.25 s part phrases.
    • A phrase's opening is the median of its first 25 voiced frames.
    • Takes under 8 kHz, all-zero takes and takes with fewer than two phrases are unmeasured. An unmeasured first take does not trip.
  • Redraw:
    • The register redraw is the last draw. It is seeded salt + k after any silence redraws, and starts only within the same budget. That budget is the lower of --silence-redraw-budget-s and X-Deadline-S, which is read whenever the guard is on.
    • The register redraw reuses the current prompt and applies no controls filter of its own.
    • The redraw is sent only if it does not end silence and has a strictly smaller jump. Ties keep the first take, and a length redraw may replace a stop take.
    • An unmeasured redraw can win only with the silence guard configured.
    • If the register redraw ends silence, the remaining silence redraws run before the comparison, and the held take is never overwritten.
  • Headers: with the guard configured, whole successful replies carry X-Register-Trip and X-Register-Redraws, each 0 or 1. X-Register-Trip is 1 when a measured take tripped. X-Register-Redraws is 1 when the register redraw was admitted, even if the first take is kept. Streams and errors omit both. Register redraws do not count toward X-Silence-Redraws.
  • Logs: register jump= for each trip, and register unmeasured: with the reason for an unmeasured take.
  • Streams are never measured or redrawn.
  • Example, illustrative only: --register-redraw-st 6 --register-redraw-high 50 --register-high-hz 300. Thresholds are calibrated on the served voice, as docs/speech-redraws.md#register describes.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: a238eb79, on the silence-redraws PR's 49ea53bd, on main d1018b31. Host tests: Linux aarch64, Zig 0.17.0, CPU only, no MLX or PyTorch. GPU run: one NVIDIA GB10, native CUDA build (-Dsm=121), no MLX or PyTorch, checkpoint fishaudio/drama-3 with its codec.pth (revision not recorded), built-in voice. Stock is upstream d1018b31. The candidate is ca60e9c8, an integration of all the open Drama patches on d1018b31, this one included, not this branch's tip.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: speech returns PCM, so PCM is compared by SHA-256.
    • GPU setup: 18 server launches, one per arm and seed salt (TENSORFOLD_SEED_SALT 0, 10 and 20), each sent the same 10 public synthetic texts: 180 requests, all complete. Every server ran with --parallel 1 --no-drafts --prompt-cache-gib 0 --context 4096 and TF_DRAMA_PREFILL_ROWS=1, which keeps the candidate on stock's prefill schedule.
    • Arms, with illustrative thresholds that are not calibrated for any voice: stock; the candidate without guard flags ("off"); --silence-floor-dbfs -50 --silence-seconds 8 ("base"); base plus --silence-onset-s 2 --silence-onset-voiced-s 0.4 --silence-mid-s 2 --silence-mid-min-voiced-s 0.4 ("silence"); silence plus --silence-redraws 2 --silence-redraw-budget-s 60 --silence-redraw-controls '' --short-reply-ratio 0.6 --short-reply-chars-per-s 12 ("redraw"); and --register-redraw-st 6 --register-redraw-high 50 --register-high-hz 300 --silence-redraw-budget-s 60 ("register").
    • All checks passed. Off equals stock byte for byte on all 30 replies. Guard headers appear exactly when their option is set. Every guarded reply where no guard fired equals off byte for byte. Each redraw counter equals the redraws that finished with audio. A redraw ran exactly when the silence arm's take ended silence or was judged short. Each of the 22 silenced takes in the base and silence arms is a prefix of the off audio.
    • This PR: the register guard was not exercised. No reply tripped: X-Register-Trip and X-Register-Redraws were present on all 30 register-arm replies and summed to 0, and all 30 equal off byte for byte. The run shows only that the measure leaves untripped replies unchanged; a trip and its redraw are covered by the host tests below.
    • Synthetic socketpair tests against a scripted engine that plays synthetic harmonic tones show two things. With the flags omitted, a high-onset take is submitted once and sent as drawn. The register redraw uses exactly seedFor(prompt, salt + k) after any silence redraws.
  • Decode speed before and after, from tools/bench_openai.py: not measured; the GPU run compared PCM, not speed. The pitch measure runs on the CPU after a whole take, only with the flags set. A redraw runs only after a trip and within the budget.
  • Prompt speed before and after: the cold first request's ttft_s from tools/bench_cache.py --require-cold on a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: n/a. The first take's prompt path is unchanged, and the register redraw reuses the current prompt.
  • Tests run, with pass, fail and skip counts:
    • zig build test --summary all: 213/213 steps, 1848/1852 passed, 4 skipped. A first run timed out after 3600 s, with cortheon linear-time and benchmark-stream timing failures in untouched code.
    • CUDA_VISIBLE_DEVICES= zig build test-cuda-host --summary all: 131/131 steps, 1236/1240 passed, 4 skipped.
    • fuzz-cortheon alone: 11/11.
    • test-kernel-contract: 65/65.
    • test-golden: 306/319 equal, 0 unexpected differences; additional corpus 26/26.
    • Native and drama3-generate build: 101/101 steps.
    • tools/zig/test_speech_flags.py: 1 test passed.
    • Each of 22 mutations of the measure and redraw failed a test.
    • The later metadata, retry-pipeline and unmeasured-logging commits passed formatting, zig build test, the CUDA-host suite, the native build and the speech-flag test again. Goldens stayed at 306/319 and 26/26 through the retry-pipeline change.
    • After merging the silence-redraws branch at 37079ece:
      • zig fmt --check passed.
      • zig build test --summary all: 213/213 steps, 3011/3025 passed, 14 skipped.
      • CUDA_VISIBLE_DEVICES= zig build test-cuda-host --summary all: 131/131 steps, 399/399 executed tests passed (unchanged steps cached).
      • The native build: 98/98 steps.
      • tools/zig/test_speech_flags.py: 1 test, OK.
    • At 7fc18a07, the unsquashed branch tip, after merging the silence-redraws tip 2e6d4858, which changes one plain-speech test input: zig fmt --check passed, and zig build test --summary all passed 213/213 steps, 3011/3025 tests, 14 skipped.
    • At a238eb79, which squashes that branch over 49ea53bd: zig fmt --check passed, and zig build test --summary all passed 213/213 steps, 3012/3026 tests, 14 skipped.
  • Not run, and why: Metal compilation, Metal device synthesis and performance measurements, because no Metal host was used and the GPU run measured PCM only. The detector ran on speech in the GPU run but never tripped there; trips are checked on synthetic tones only. No threshold values are proposed, because they describe a voice and are calibrated per voice. The new tests do not compile on the base, which lacks the register guard. No GPU kernel changed. Frozen test data was not edited.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

--allowed-controls keeps listed delivery controls in a normalized form and strips other cue-only brackets before speech input validation; contextual and unknown brackets stay as written. The built-in cue word list holds only words from tags in Fish Audio's public sources.
Add --silence-floor-dbfs and --silence-seconds so native Drama speech can stop after a sustained run below an explicit frame-power floor, keeping the audio and reporting the finish as silence. The guard is off unless both flags are set and is refused for non-speech models.
Bring the opt-in --allowed-controls filter onto the silence guard so silence redraws can reuse its rules. The two changes touch separate flags; only the changelog and the flag parser needed joining.
Add --silence-redraws with an optional --silence-redraw-budget-s and --silence-redraw-controls so a whole reply that ends as silence is drawn again with a salted seed while the budget and X-Deadline-S allow. Streams are never redrawn, and enabled redraws report X-Silence-Redraws.
Add --register-redraw-st, --register-redraw-high and --register-high-hz so a whole reply whose later phrase opens well above the others in a high register is drawn once more, keeping the take with the smaller jump. Configured replies report X-Register-Trip and X-Register-Redraws.
@ashhart

ashhart commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev for register thresholds that are all-or-none with no defaults, the strict smaller-jump selection that keeps ties on the first take, and the test that keeps the held take safe through later silence redraws (zig/src/server/speech_register_test.zig:40, :185, :234). The register change raised nothing new for us, so we are carrying it onto current main ourselves on top of #1160, with your commits kept as yours; what it inherits from #1152 and #1157 is fixed once in those PRs, and since #1161 also changes speech_redraw.zig and speech.zig, we will combine the two when the second lands and add a test with both rules set. Since your GPU run reports no register trip, the device runs on a GB10 and on Metal will include speech that actually trips the guard and compare its redraw with a direct synthesis at the same seed, and then it lands. You need not rebase; if you are in the middle of a change, please tell us so we do not collide.

- Synthema, Ash's AI Assistant.

ashhart added a commit that referenced this pull request Oct 24, 2026
… both set

- zig/src/server/speech_register_test.zig: with both rules set, short stops are redrawn without a register measurement, a take the short rule leaves is still register-redrawn, a register retry that ends short reenters the short redraws, and the held take beats takes the short rule tripped; validation and the refusal cover both rules.
@ashhart

ashhart commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Landed on main as 4e61579 with a maintainer fix-up (3101731) that tests the short and register rules together, thank you @plotarmordev. Replies that jump to a high register are redrawn. On a GB10, the default Drama output stayed byte-identical to main on six inputs with these options off, repeats were 6/6 equal, and concurrent equalled solo. The speech, Drama, server and golden host suites pass on current main.

- Synthema, Ash's AI Assistant.

@ashhart

ashhart commented Oct 24, 2026

Copy link
Copy Markdown
Owner

This shipped in TensorFold 1.1.4: https://github.com/ashhart/TensorFold/releases/tag/v1.1.4

Thank you @plotarmordev for the contribution.

- Synthema, Ash's AI Assistant.

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.

2 participants