Skip to content

feat(speech): add a mid-utterance rule to the silence guard - #1159

Closed
plotarmordev wants to merge 2 commits into
ashhart:mainfrom
plotarmordev:feat/silence-mid
Closed

plotarmordev wants to merge 2 commits into
ashhart:mainfrom
plotarmordev:feat/silence-mid

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

Stacked on the silence-guard PR (#1157) and reviewable after it; independent otherwise.

Adds a mid-silence rule to the Drama 3 silence guard: if speech ends during a silent run of at least --silence-mid-s seconds after at least --silence-mid-min-voiced-s seconds of voiced audio, the reply finishes as silence instead of stop, with all audio kept. It is off unless both flags are given.

  • --silence-mid-s SECONDS: above 0 and below --silence-seconds, so it needs the guard's floor and duration.
  • --silence-mid-min-voiced-s SECONDS: required with it. It must be positive and finite, is cumulative across pauses, includes equality and has no default.
  • The rule only relabels the finish; it never cuts audio. Replies ended by the frame cap (length) or by the tail rule are not mid trips.
  • With --silence-mid-s set, whole replies carry X-Silence-Mid-Trips: 0 or 1. Streams end with the X-Finish-Reason: silence trailer and no count, and errors carry none. Without the flag the header is absent.
  • Any silence flag on a non-Drama model is refused at startup. With illustrative values, --silence-floor-dbfs -50 --silence-seconds 8 --silence-mid-s 6 --silence-mid-min-voiced-s 2 logs drama3: silence guard on: a reply ends after 8 s below -50 dBFS, or as silence when it stops after 6 s below it with at least 2 s voiced.
  • This is an energy judgement at end of speech: a reply that ends naturally after a pause longer than --silence-mid-s is marked. Choose it above the longest silence that ends normal replies, and the voiced minimum, on built-in or public speech; no value is recommended.
  • This overlaps the onset pull request in the guard config, CLI flag table, usage line, README and changelog. Each conflict resolves by keeping both sides.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: 18f92204, on the silence-guard PR's 75736ad0, 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. The rule reads decoded audio at end of speech and never changes tokens or samples.
    • 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 mid rule tripped twice, both on the trailing text (salts 10 and 20). Each reply carries X-Silence-Mid-Trips: 1 and finishes silence with audio byte-identical to the off reply, where the base arm finished the same reply stop. Every other silence-arm reply carries X-Silence-Mid-Trips: 0.
    • A host test drives the real post-frame decode, end-of-speech judgement and finish, with the CUDA wait faked through the driver table. Whole and streamed requests get the same reason and published result, and results are unchanged with the rule off.
  • Decode speed before and after, from tools/bench_openai.py: not measured; the GPU run compared PCM, not speed. The rule adds one comparison at end of speech.
  • 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 rule runs at end of speech, after frame generation.
  • Tests run, with pass, fail and skip counts:
    • CUDA_VISIBLE_DEVICES= zig build test --summary all: 210/213 steps, 2979 passed, 1 failed, 14 skipped.
    • CUDA_VISIBLE_DEVICES= zig build test-cuda-host --summary all: 129/131 steps, 921 passed, 1 failed, 4 skipped.
    • Both failures are cortheon fuzz: every reader takes linear time on long inputs, a wall-clock test that failed the same way on the base under the same host load. No Cortheon file is changed.
    • zig build test-kernel-contract --summary all: 65 passed. zig build test-golden --summary all: 306/319 equal with 0 unexpected differences, plus 26/26.
    • zig build native drama3-generate -Dsm=121 with the CUDA toolkit's nvcc: linked. tools/zig/test_speech_flags.py: 1 passed.
    • zig fmt --check build.zig zig and git diff --check are clean. tools/zig/lean_check.py reports the same 444 findings as main, none new.
    • Thirteen mutants of the rule, validation, refusal, startup line, CLI, header and published result were each killed by the new tests.
    • The counts above predate the last two fixes (the zero count and the required voiced minimum). After those fixes, formatting, test, test-cuda-host, test-golden, the native build, the speech-flag test and the lean check passed again with no failures; counts were not recorded. Since then the code has changed only by illustrative values in one unit test (fa18b3ab). 18f92204 squashes that branch over 75736ad0, with an identical tree.
  • Not run, and why: Metal compilation and device runs, because no Metal host was used. CUDA decode speed was not measured. Concurrent against solo was not run. The new host test skips off CUDA builds. No GPU kernel changed and no frozen test data was 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.

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.
Add --silence-mid-s with a required --silence-mid-min-voiced-s so a synthesis that has voiced enough finishes as silence when end of speech falls in a long run below the floor. Whole replies report the X-Silence-Mid-Trips count when the rule is configured.
@ashhart

ashhart commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev for a mid rule that only relabels the finish at end of speech and never cuts audio (zig/src/core/speech_guard.zig:89-94), with the voiced minimum inclusive and cumulative and tests for both. We are carrying it onto current main ourselves on top of #1157, with both commits kept as yours; our separate commit on #1157 fixes the inherited Metal host-test link and moves #1157's silence guard test into zig/src/server/cli_test.zig, which also keeps this branch's zig/src/server/cli.zig within 600 lines after the rebase (it would be 601), and since #1158 also changes speech_guard.zig, we will combine the two when the second lands and add a test with both rules set. Then it goes to the device runs on a GB10 and on Metal, checking that a mid trip leaves the audio byte-identical to the tail-only reply and that X-Silence-Mid-Trips reads 0 or 1 as documented, and 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
… set

- zig/src/core/speech_guard.zig: with both rules set, an onset cut lands on the same sample as the onset rule alone and is no mid trip, the mid relabel matches the mid rule alone, and validation, the startup sentence and the refusal cover both rules.
- zig/src/native/drama_host.zig: the same two cases through the host's PCM callback and finish path, whole and streamed, each against its rule alone.
ashhart added a commit that referenced this pull request Oct 24, 2026
…st.zig

- Landed after #1158 and #1159, this PR takes zig/src/server/cli.zig to 606 lines, so its two remaining flag tests (--device and --segments, and the GPU engine's flags) move unchanged to zig/src/server/cli_test.zig, which reaches the private helpers through a test-only cli.Test, as log.zig's Test does.
@ashhart

ashhart commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Landed on main as 79ffa80 with a maintainer fix-up (30d76b2) that tests the onset and mid rules together, thank you @plotarmordev. 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 closed this Oct 24, 2026
@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.

@ashhart ashhart added the landed Landed on main by the maintainers; the commits keep the contributor's authorship label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants