Repository navigation
Send Hex the whole recording, in chunks cut at quiet moments - #110
Open
liam-cyberpro wants to merge 8 commits into
Open
liam-cyberpro wants to merge 8 commits into
liam-cyberpro wants to merge 8 commits into
Conversation
Hex, the Windows Parakeet engine and the command transcriber all spread text-only answers over time with `hex::spread_words`, so two engines depended on the Hex client for a generic helper. It now lives in `speech_plan::spread`, which takes a list of spans: each span gets the words whose middle falls in its share of the speech, so no word lands between spans. With one span it gives exactly what `spread_words` gave. `audio::SAMPLES_PER_MS` replaces three local copies of 16. No behaviour change.
Fixes kitlangton#89 and kitlangton#90. Hex was sent only the speech islands that cleared a loudness bar, and islands shorter than 120 ms were dropped, so quiet speech next to louder speech, and a lone short word like "Wait.", never reached Hex. Hex itself hears them fine. `speech_plan::Plan` now cuts the whole recording into chunks of at most 30 s, each cut at the quietest 50 ms window at least 15 s into it, so the chunks tile the recording with no padding and no overlap. Loudness no longer decides what is heard, only when: a chunk is left out only when it has no voiced window (silence or steady noise, where a model may invent words), and Hex's text for a chunk is spread over the voiced spans inside it. Voiced spans use a more sensitive threshold than `audio::speech_islands` (2x the noise floor, between 0.001 and 0.01 RMS, no minimum length). `audio::speech_islands` is split into `window_rms`, `noise_floor` and `islands_above` so both share one pass; its results are unchanged. Decisions: - A chunk Hex refuses (4xx) now fails the whole recording, which then falls back to Apple, instead of being skipped with a log line. A skipped 30 s chunk would silently lose the very speech this fixes. - `MAX_CLIPS` (24) is gone for Hex: a recording takes one request per 30 s chunk. `TOTAL_DEADLINE` (180 s) still applies, checked before each chunk; past it the recording falls back to Apple as before. - An empty Hex transcript no longer says `estimated: true` (no words were placed), which only affects what scrawl.json records. Hex's own "too quiet, send everything" fallback is gone: chunks always cover everything. Windows' Parakeet still plans by speech islands: `plan_clips` moves verbatim into `src/win/speech.rs`, beside its own 480 ms fallback, so its behaviour is unchanged. Tests use synthetic signals: chunks tile the recording and stay under 30 s, a quieter phrase (kitlangton#89) and a lone 100 ms word (kitlangton#90) both reach the recognizer, the cut lands on the quietest window, silence and noise send nothing, text stays inside its chunk's voiced spans, and against a fake Hex the samples sent add up to the whole recording and a refused chunk fails the recording.
Windows' Parakeet planned its requests by speech islands, the same loudness-gated planner that lost quiet and short speech on Hex (kitlangton#89, kitlangton#90). It now runs on `speech_plan::Plan` too: the whole recording in chunks of at most 30 s cut at quiet moments, silence and steady noise left out. The model's measured times are kept: it answers `Heard::Timed`, and `speech_plan::transcribe` moves its words and segments from the chunk's clock to the recording's. A chunk without word times is spread over its voiced spans and marks the transcript `estimated`, as a clip without word times did. Chunks cover the recording, so the 200 ms clip padding, `plan_clips` and the 480 ms fallback are gone, and `audio::speech_islands` is kept for tests only. Behaviour change: Parakeet now also hears quiet stretches, so it runs on more audio per recording.
A chunk was left out whenever no window reached the voiced level (2x the noise floor, at least 0.001 RMS). Speech that stays below that, such as syllables at 1.6x a steady floor or a whisper over digital silence, was therefore never sent, and the recording came back as an empty transcript that counted as a success, so it never fell back to Apple. The old planner sent such a recording whole. A chunk with no voiced window is now still sent when it lasts at least 480 ms and its level moves: its loudest window is above 0.0001 RMS and 1.25x the chunk's own noise floor. Quiet speech still rises and falls, while silence and steady noise stay flat (Gaussian noise varies by about 10% across 50 ms windows), so those are still never sent. Sending was chosen over failing to Apple because it works the same for Windows' Parakeet, which has no Apple to fall back to. Also undoes a change this branch did not need: a Hex transcript is `estimated` again even when Hex heard nothing, as before. The docs sentence about which chunks are left out is updated to match, and `Plan` no longer derives an unused `Clone`.
The previous commit sent any chunk without a voiced window whose level moved, as long as the chunk lasted 480 ms. Two problems: - Band-limited steady noise (fan, traffic, handling rumble) moves more than 1.25x across 50 ms windows, so a noise tail after finished speech was sent, and a recognizer could invent words over it. - A quiet word after a long silence could land in a last chunk shorter than 480 ms and be dropped. The fallback now applies only when the recording has no voiced window at all, which is the case the old planner's whole-recording fallback covered, and the 480 ms minimum applies to the recording rather than to each chunk. Quiet speech after louder speech in the same recording is left out when it never reaches the voiced level, as on main. Tests: white noise sends nothing; 10 s of speech then 40 s of noise low-passed at 100 Hz sends one chunk (two before this change); a 200 ms whisper after 30 s of silence is heard.
The fallback for speech under the voiced level only applied when no window in the recording was voiced. The voiced level is lower than the old island level, so a recording whose loudest speech was voiced but still under the old level (about 0.001 to 0.005 RMS in a quiet room) lost any quieter speech in its other chunks, although the old planner sent such a recording whole. The fallback now applies exactly when the old planner sent everything: the recording lasts 480 ms and has no speech island of 120 ms at the old level (`audio::island_threshold`, factored out of `speech_islands`). Within it, only chunks whose level moves are sent, so the branch never hears less than the old planner except flat chunks (silence, white noise). Noise after speech that reached the old level is still not sent. Tests: a 0.002 phrase then a 0.0008 whisper 29 s later, and 0.003 speech then a 0.0008 word 35 s later, are both heard (the whisper and the word were dropped before this change); a recording of 100 Hz rumble alone is still sent whole, as the old planner sent it.
The doc on the quiet-speech fallback now says what it guarantees only for recordings the old planner sent whole, since outside that case the old planner also sent clip padding and merged gaps. Tests: a 100 ms click (an island the old planner dropped as under 120 ms) followed by a quiet word 30 s later still falls back and hears the word; the 0.003-speech test also checks that the old planner found no island; rumble alone being sent whole is its own test.
The module doc and the transcription docs said every word is heard however quietly it was said, and that only silent or steady-noise chunks are left out. Speech that stays under the voiced level in a recording with audible speech elsewhere is still left out, as on main, so both now say that short or quiet speech is heard once it reaches the voiced level, and below it only when nothing else in the recording is audible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #89. Closes #90.
Hex was sent only the speech islands that cleared a loudness bar, and islands under 120 ms were dropped, so quiet speech beside louder speech, and lone short words, never reached Hex.
Eight commits. The first three carry the change, each reviewable alone:
speech_plan.rs. No behaviour change. Hex, Windows and Command sharedhex::spread_words; it is nowspeech_plan::spread.Commits 4-8 are review follow-ups to the planner in
speech_plan.rs: speech too quiet to count as voiced is still sent, and tests pin when.Decisions worth a look:
MAX_CLIPSis gone for Hex;TOTAL_DEADLINE(180 s) still applies per recording.Measured with Apple standing in for Hex (Hex not installed here):
#90 could not be reproduced with synthetic speech; a unit test covers the 100 ms case.
Tests:
cargo test --lockedpassed on macOS and Windows in my fork's CI on 7d31ce1 (run https://github.com/liam-cyberpro/scrawl/actions/runs/40180522272). New tests use synthetic signals only.#94 touches the same Hex planning code; either can land first, and the other rebases in about 10 lines (Handy would call
speech_plan::Plan::new(&s).voiced()andspeech_plan::spread).Review: Claude code review: passed. GPT code review: asked for a per-chunk quiet fallback after loud speech; not adopted, because main never did that and it re-sends low-frequency noise tails after speech (measured on a 100 Hz rumble).