Skip to content

Plugin 1.1.0: recognition 3–4× faster (window fitting the recording, one thread pool, CPU variants), no dictated text in the log - #6

Open
4di-hello wants to merge 16 commits into
LeanBitLab:masterfrom
4di-hello:pr/faster-recognition
Open

4di-hello wants to merge 16 commits into
LeanBitLab:masterfrom
4di-hello:pr/faster-recognition

Conversation

@4di-hello

@4di-hello 4di-hello commented Nov 29, 2026 •

Copy link
Copy Markdown

What changes

  • Window fitting the recording: Whisper always computed a 30 s window, also for 3 s of speech. For recordings under 30 s the window now fits the audio (audio_ctx = seconds × 50 + 64, rounded up to 64). That makes the encoder several times faster. Longer recordings are unchanged.
  • Repetition guard: normal Whisper models are trained on the full 30 s window and sometimes write a part twice with the shorter one. If the text repeats itself (a run of 3+ words directly repeated, or the same 5 words twice anywhere), the audio is recognized once more with the full window. That only costs time when it happens; if that second run fails, the first result is kept. Languages written without spaces (Chinese, Japanese, Thai, …) keep the full window, since the check can't see repeats there.
  • One thread pool on the fastest cores (small patch to whisper.cpp in patches/, applied by CMake): without it ggml starts and ends threads for every computation step, i.e. for every decoded token. The threads are pinned to the fastest cores (by cpuinfo_max_freq); if those can't be read, nothing is pinned, as before. One pool per thread count, so changing the thread setting is safe; the fast cores are read from the process, not from the calling thread (ggml pins that thread to the first pool's cores, which made a later, bigger pool share them: 19–45 s instead of about 1 s in a test). If no CPU backend can be loaded, the model fails to load with an error instead of crashing.
  • CPU backend variants loaded at runtime (ARMv8.0 up to ARMv9.2 with dotprod, i8mm, SVE, SME and KleidiAI kernels, x86_64 likewise): ggml picks the best one for the phone, as in the offline AI plugin. The arm64 build therefore runs on every ARMv8-a CPU, so the release no longer builds the separate compat APK (-PcompatCpu=true still works but has no effect; CpuSupport stays, it just never refuses now). README and release notes (docs/release_notes/v1.1.0.md) are updated. The arm64-only APK with all variants is 4.4 MB. Note: ggml's CMake downloads the KleidiAI kernels during the build (fine on GitHub Actions; an offline build would need GGML_CPU_KLEIDIAI=OFF).
  • whisper.cpp 1.9.2 → 1.9.6, which also fixes CVE-2026-110810 (out-of-bounds read when loading a model, fixed in 1.9.5).
  • Robustness: the thread count is limited to the cores the app may use (each count keeps its pool, so this also keeps the number of pools small). Loading and recognition catch every exception (e.g. a model file asking for more memory than there is) instead of ending the process. The text comes back as UTF-8 bytes and is decoded in Kotlin, since JNI's NewStringUTF only takes modified UTF-8. Debug-level engine logs are not passed on.
  • Privacy: the recognized text and the prompt are no longer written to the system log, only lengths and times.
  • -Pvoice.abis=arm64-v8a builds one APK with only these ABIs (whisper.cpp takes long to build), libraries for 16 KB memory pages, version 1.1.0 (110).

The interface to the keyboard is unchanged, so the current LeanType works with it as before. The keyboard PR in LeanBitLab/LeanType (it links here) adds an optional speed display and the name of the imported model.

How we tested

Phone: Dimensity 9400+ (1× Cortex-X925, 3× Cortex-X4, 4× Cortex-A720), German. Two test dictations: one sentence (about 3–4 s) and three sentences (about 11–12 s). Measured with the speed display of the keyboard PR: time from the last spoken word until the text is there.

It started with a measurement of the current plugin: a single sentence took 7.7 s, three sentences hardly more (8.9 s). A fixed base, because the full 30 s window is computed every time. Turbo took 32 s. While measuring we also noticed that the app didn't show which model was active (imported models all have the same name in the plugin), so the keyboard PR shows it now.

Model Plugin short long Notes
Small current 1.0.4 7.7 s 8.9 s
Turbo current 1.0.4 – 32.2 s
Turbo shorter window + thread pool 5.8 s 16.7 s short sentence written twice → repetition guard
FUTO Multilingual-244 (Small, ACFT) same 3.4 s 7.0 s no repetition: ACFT models are trained for short windows
FUTO Multilingual-244 + CPU variants (this PR) 1.5 s 5.5 s
Small (from the model list) this PR 2.0 s 5.1–5.6 s once wrote the beginning twice ("Bruder" / "Bode") → guard extended to "same 5 words anywhere"

Threads (FUTO-244, this PR, long text): 4 threads 2.7 s, 6 threads 4.5 s, 8 threads 8.2 s recognition after the recording (short sentence: about 1 s with 4 or 6). With the persistent pool every step waits for the slowest core, so the fast cores win, most clearly for longer texts where decoding dominates; with the old per-step threads 8 used to be faster than 6. 4 stays the default.

Repetition guard checked against the real outputs: the doubled text from the Small test is caught, the clean texts are not.

Recognition quality didn't change; the remaining mistakes ("Weise" instead of "Vase") are the known weakness of Small-sized models. Tested on arm64 only; armeabi-v7a and x86_64 build, but I couldn't try them on a device.

It was a lot of testing: many builds, measurement series with three models and two dead ends (Turbo repeating itself, the narrow repetition check). But I think the effort was worth it: a short sentence is there in 1.5–2 s instead of 7.7 s.

Added on 30.11.

  • Cancelling really stops the recognition: cancelling a session, also when the keyboard gives up after its timeout, now stops the running whisper.cpp computation after its current encoder pass or decoding step (abort_callback). Before, it ran to the end and every following dictation waited behind it. With a large model this showed up as "Voice processing timed out" for the next dictations as well. Each session also has its own cancel flags now: a new session no longer resets the cancel of the previous one, and a cancel arriving just as a recognition ends can't stop the next one.
  • Import result: the message of the model state ends with [imports=N; importing | last=ok | last=failed: reason], so the keyboard can tell whether an imported model is really ready (keyboard PR Voice input: optional speed display, name of the imported model, thread labels as measured LeanType#1002). The counters live per process, so a service created again during an import still reports it. The interface is unchanged.
  • Tested on the phone: a broken download was reported as "the model could not be loaded", the FUTO model and whisper-large-v3-turbo-german (q8_0) as ready. Since the abort fix, no dictation hung behind an earlier one; I didn't provoke a timeout on purpose.
  • Merged master (1.0.5 with the caller check); no conflicts left.

All work and measurements were done with Claude Code; I tested every version on the phone.

🤖 Generated with Claude Code

4di-hello and others added 10 commits November 28, 2026 14:50
…ol, whisper.cpp 1.9.6

- Whisper computed a full 30 s window (1500 audio frames) even for 3 s of speech.
  Below 30 s the window now fits the audio with some room (audio_ctx).
- One thread pool for the CPU backend on the fastest cores, kept while the process
  runs (patch to whisper.cpp, applied by CMake). Without it ggml starts and ends
  threads for every graph, so for every decoded token.
- whisper.cpp 1.7.4 -> 1.9.6, OpenMP stays off.
- The log has only numbers (lengths, times), never the recognized text or the prompt.
- -Pvoice.abis=arm64-v8a builds only that ABI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The debug build type sets ndk abiFilters too, which conflicts with ABI splits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured with large-v3-turbo (not trained for a shorter window): one sentence of 3 s
came out twice. If a run of at least 3 words directly repeats itself, the audio is
transcribed again with the full 30 s window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The arm64 build was compiled for ARMv8.2 (dot product, FP16) only, so newer CPUs
could not use i8mm, SVE or SME. ggml's CPU backend is now built in variants
(GGML_BACKEND_DL, GGML_CPU_ALL_VARIANTS, KleidiAI on arm64) and the best one for
the phone is loaded at runtime from the library folder (JNI_OnLoad). The libraries
are extracted for that, with the shared C++ runtime. The thread pool patch looks up
the CPU backend's functions instead of linking them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-plus

Normal Whisper Small with the shortened window wrote the first two sentences of a 12 s dictation
twice, with small differences ("Bruder" / "Bode"), which the direct-repeat check missed. Then the
audio is recognized again with the full window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r window

- One thread pool per thread count, never freed: the CPU backend pauses the pool it used before
  when it gets another one, so freeing it was a use after free
- No CPU backend loaded: init fails cleanly instead of crashing the process
- No shorter window when it would be the full 1500 frames anyway, nor for languages written
  without spaces (the repetition check can't see repeats there)
- If the second run with the full window fails, the first result is kept
- Release: no compat APK any more (the CPU variants cover every ARMv8 CPU), release notes for
  v1.1.0, README updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ggml pins the thread that creates a thread pool to that pool's cores. The cores for the next pool were
read from that same thread, so after 4 threads a pool for 6 got only the 4 fast cores: 6 threads on
4 cores, which waits at every step (measured 19-45 s instead of about 1 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4di-hello and others added 5 commits November 29, 2026 19:03
… JNI, text as bytes

- Threads limited to the cores the process may use: more only wait for each other, and since every
  thread count keeps its pool, any number from a caller could otherwise create pools without end
- init and transcribe catch every exception (e.g. a model file asking for more memory than there is)
  instead of ending the process; JNI resources are released through guards
- The text comes back as UTF-8 bytes, decoded in Kotlin: NewStringUTF only takes modified UTF-8
- Debug-level engine logs are never passed on

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- whisper.cpp asks an abort flag before every computation step; cancelling a session (also after the
  keyboard's timeout) stops its running recognition instead of letting it hold up the next dictation
- Each session has its own cancel flags: a new session no longer undoes the cancel of an earlier one
- The model state tells whether an import is running and how the last one ended (ok, or the reason),
  so the keyboard can confirm that a model is really ready

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…per process

- Marking the transcribing session and aborting it happen under one lock, so a cancel that arrives just
  as a recognition ends can't stop the next one
- Wording: whisper.cpp checks the abort flag after each encoder pass and decoding step
- Import counters and the import executor live per process: a service created again during an import
  reports it correctly and doesn't start a second import alongside

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant