hex/android/app
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ryan Vogel f183293f9b
Android dictation: trim the quiet, cap runaway decodes, ✕ stops the decode, notes over the update line (#2601)
* Android: dictation trims the quiet, caps runaway decodes, stops on ✕, says when it hit 1 minute

Why: a tap on the Hex key listens until ✓ or the 60 s limit (Gboard's habit is tap,
talk, wait), and Whisper then transcribed the whole minute: 3 s of speech in a 60 s
recording took 8.5x as long as the 3 s alone and ended with an invented "you" (in
Swedish, the sentence twice). A language small handles badly (Kazakh told English)
looped to Whisper's 220-token limit and retried with five sampled decoders at each of
up to five temperatures. ✕ only marked a dictation cancelled while its decode ran on,
so the next one queued behind it. Hex Preview's update line hid every dictation note.

What changed:
- MicCapture hands Whisper only the speech: 0.3 s before the first voiced 40 ms block
  to 0.5 s after the last (the same -48 dBFS test as "No speech heard"), at least
  1.1 s as before; pauses inside stay. speechSpan is the rule, unit-tested in
  InsertionTest.
- hexspeech.cpp: max_tokens = min(220, ceil(min(sec, 30) * 15) + 16), greedy.best_of
  = 1, and one retry at 0.2 (temperature -0.8, step 1.0: whisper.cpp decodes greedily
  at <= 0). Replaces whisper's default fallback (five more temperatures, five decoders
  each). A single retry at 0.6 or 1.0 was tried and invented fluent English or mixed
  scripts, so it is not used.
- ✕, Home's Cancel and leaving the field abort the decode in progress through
  whisper.cpp's abort_callback (Whisper.abort(job), MicCapture's job numbers); an
  aborted decode no longer falls back to the bundled model.
- A recording that reaches 1 minute inserts its text with "Stopped at 1 minute"
  (English and Simplified Chinese, the languages the keyboard's strings carry).
- StripView: a dictation's note wins over the notice line (Hex Preview's update
  line) until typing, a tap or the next dictation; a note that comes with text
  shares the line with Undo dictation.
- Debug-only HexSpeech log: kept span, decode ms and outcome (no audio or text).
- README: what Whisper hears, the decode limits, ✕ stopping the decode, the notes.
Leaving the field still discards a dictation, as before.

Verified: native macOS build of the app's pinned whisper.cpp (d1be6fd, CPU, 2
threads; harness mirrors hexspeech.cpp and the trim) with the downloaded small model:
the 40 benchmark clips give identical text (WER 5.61% before and after) and the 15
long clips identical text (5.69%); 3 s of speech then quiet to 15 s 3113 -> 740 ms,
to 60 s 6285 -> 745 ms without the stray "you" (Swedish 6380 -> 769 ms, once);
Kazakh told English 1892 -> 803 ms (3.6 s) and 6779 -> 4200 ms (10.5 s); room noise
1722 -> 732 ms. Abort returns after the encoder pass under way (whisper.cpp checks
after each encoder pass and token) and the context decodes the next clip unchanged.
./gradlew :app:testDebugUnitTest :app:assembleDebug pass (76 tests).

* Android: a click or the tap on ✓ doesn't stretch what Whisper hears

Why: on the emulator, two loud 40 ms blocks arrived 26 s after the speech in a
60 s tap recording, and the trim kept everything up to them (0.8-30.3 s: the full
encoder window, 4.4 s instead of under 1 s). On a phone the tap on ✓ itself, a
knock or a click is such a block.

What changed: SpeechEdges finds the speech's start and end from MicCapture's
40 ms blocks: voiced blocks less than 300 ms apart form a stretch, which counts as
speech once it holds 120 ms of voice. One or two loud blocks away from the speech
never do; any word is longer. With no stretch at all, Whisper hears the whole
recording, as before the trim. Replaces the first and last voiced block as the
trim's edges. Unit-tested in InsertionTest.

Verified (native harness, the app's whisper.cpp with dev's fresh state per
dictation, small model): the 40 benchmark clips and 15 long ones give the same
text as dev (WER 5.61% and 5.69%); 3 s of speech, quiet and an 80 ms -30 dBFS click
at 14.6 s: 3220 ms with the first cut (kept 15 s), 791 ms now (kept 2.6 s), same
text. ./gradlew :app:testDebugUnitTest :app:assembleDebug pass.

* Android README: what counts as speech for the trim

The trim's edges are now stretches of voice (4b9adbd3d), not the first and last
voiced block; the README said the latter. Docs only.

* Android strip: swiping ends a notice as typing does; a note beside Undo isn't cut short

Why: swipe typing (#2599) shows the word so far in the suggestion slots, which a
strip notice (Hex Preview's update line) hides; typing ended the notice for the
field, swiping didn't. On the emulator, "Stopped at 1 minute" beside Undo
dictation read "Stopped at 1 ..." with the menu key at full width.

What changed (StripView only): a swipe under way (KeyboardEngine.swiping) ends
the field's notice as a typed word does; while a dictation's note shares the line
with Undo, the menu key shows ⋯ as it does beside suggestions.

Verified: ./gradlew :app:testDebugUnitTest :app:assembleDebug on the Studio (124
tests). The emulator check of both is pending (the emulator is on a release gate).
2026-11-23 18:57:09 -05:00
..
src Android dictation: trim the quiet, cap runaway decodes, ✕ stops the decode, notes over the update line (#2601) 2026-11-23 18:57:09 -05:00
build.gradle.kts Android: Send feedback form that posts to Bellhop (#2582) 2026-11-23 15:51:14 -05:00
proguard-rules.pro Hex for Android: on-device dictation keyboard (#2074) 2026-11-20 17:27:17 +00:00