Skip to content

feat(speech): add opt-in sustained silence guard for Drama speech - #1157

Closed
plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:feat/silence-guard
Closed

plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:feat/silence-guard

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

Adds an opt-in silence guard to native Drama 3 speech, shared by CUDA and Metal: when decoded audio stays below a floor for a set time, the reply stops, keeps the audio up to that point and finishes as silence. It is off unless both thresholds are given, and with it off nothing changes.

  • --silence-floor-dbfs DBFS: mean-square power floor per codec frame (2048 samples at 44.1 kHz), at most 0, no default. Frames strictly below it are silent; a frame at or above it resets the run.
  • --silence-seconds SECONDS: the continuous silent run that ends a reply. Unset or 0 is off; a positive value needs the floor.
  • A trip keeps the audio through the frame that reaches the run and reports X-Finish-Reason: silence, as a header on whole replies and as the trailer on streams.
  • With the guard on, whole replies decode frame by frame on the existing streaming decode path so the guard can stop generation. With it off, the decode schedule, PCM and finish headers are unchanged.
  • Any silence flag on a non-Drama model is refused at startup. With illustrative values, --silence-floor-dbfs -50 --silence-seconds 8 logs drama3: silence guard on: a reply ends after 8 s below -50 dBFS.
  • This is an energy floor, not voice-activity detection. Calibrate on built-in or public speech: put the floor below quiet intended speech and the run above intentional pauses. No value is recommended.

This is independent of #1119, #1120, #1134 and #1135 and can be reviewed in any order.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: 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.
    • 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: in the base arm, 10 of 30 replies ended silence, each keeping a prefix of the off audio, and the other 20 equal off byte for byte. Finish reasons: off 23 stop and 7 length; base 18 stop, 10 silence and 2 length.
    • Host tests drive the production PCM callback and decode schedule: whole and streamed replies keep the same samples and cut at the same frame, and with the guard off the PCM is complete and whole replies still decode once.
  • Decode speed before and after, from tools/bench_openai.py: not measured; the GPU run compared PCM, not speed.
  • 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 guard reads decoded audio after frame generation and does not reach prompt processing.
  • Tests run, with pass, fail and skip counts:
    • CUDA_VISIBLE_DEVICES= zig build test --summary all -j1: 210/213 steps, 1291 passed, 3 failed, 7 skipped. The failures are wall-clock bounds in files this change does not touch: the Cortheon linear-time fuzz test and two benchmark-stream elapsed-time assertions. No bound was changed.
    • zig build fuzz-cortheon -Dfuzz-optimize=Debug --summary all, run alone: 11 passed, 0 failed.
    • tools/zig/test_speech_flags.py against the native build: 1 passed, 0 skipped.
    • zig build native -Dsm=121 with the CUDA toolkit's nvcc: 98/98 steps.
    • At the first commit: test-cuda-host 1045 passed, 4 skipped; test-kernel-contract 65 passed; test-golden 306/319 equal with 0 unexpected differences, plus 26/26.
    • 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.
    • The last test-only and README corrections were not followed by another full-suite run. 75736ad0 squashes the branch these counts come from, 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 tests were not run against main, where their fields and flags do not exist. 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.
@ashhart

ashhart commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev for a guard that stays fully off unless both thresholds are given, refuses the flags on non-Drama models before anything loads (zig/src/server/main.zig:106), and is tested through the real PCM callback for whole and streamed replies. We are carrying it onto current main ourselves, kept as yours (it conflicts in CHANGELOG.md, zig/src/core/engine_api.zig and zig/src/server/main.zig), and a separate commit of ours will link Metal, Foundation and objc on the runtime module built in metal() (zig/build/drama3_host.zig:34), as zig/build/h3_host.zig:14-17 does, so zig build check-drama-metal-host links on a Mac, and move the silence guard test from zig/src/server/cli.zig into zig/src/server/cli_test.zig to leave room for #1158 and #1159. Then it goes to the device runs on a GB10 and on Metal, including whole against streamed cuts and output with the guard off against main, and lands. You need not rebase this or the PRs stacked on it; if you are in the middle of a change on any of them, 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
… its flag test to cli_test.zig

- zig/build/drama3_host.zig: metal() links Metal, Foundation and objc on its runtime module, as h3_host.zig does, so check-drama-metal-host links and runs on a Mac.
- The silence guard flag test moves unchanged from zig/src/server/cli.zig to zig/src/server/cli_test.zig, leaving cli.zig room for the flags of the PRs stacked on this one.
@ashhart

ashhart commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Landed on main as e4e2280 with a maintainer fix-up (82e1ae1), thank you @plotarmordev. The opt-in sustained-silence guard for Drama speech is in. 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