speech: whisper-base for speech-to-text, replacing whisper-tiny
- Commit
0809b5252e6f37c8fe84543493344ba5f419b3a7- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-28 03:02 UTC (3 months ago)
- Parents
3e93142
Diff
SUPPLY_CHAIN_RISKS.md
diff --git a/SUPPLY_CHAIN_RISKS.md b/SUPPLY_CHAIN_RISKS.mdindex 01066fb649..409bf49bc0 100644--- a/SUPPLY_CHAIN_RISKS.md+++ b/SUPPLY_CHAIN_RISKS.md@@ -50,7 +50,7 @@ These servers provide data/functionality that is NOT intrinsically tied to a sin `speech` **no longer downloads a recogniser**, though TTS voices are still fetched: -- **Speech-to-text** is `whisper-tiny` int8 ONNX (~40 MB) in `speech/src/main/assets/whisper-tiny/`, run on `onnxruntime-android` by `WhisperOnnxEngine.kt`. It replaced a 117 MB runtime download of the ncnn conversion from `data.vayunmathur.com/models/whisper-tiny/`. Upstream is **`onnx-community/whisper-tiny`** on HuggingFace (an ONNX Runtime dynamic quantization of `openai/whisper-tiny`, Apache-2.0) — a **build-host** dependency only, pinned by SHA-256 and refreshed by `scripts/speech/fetch_whisper_onnx.sh`. If it vanished, shipped builds keep transcribing. Note this moved the log-mel front end and the KV-cached decode loop into Kotlin (`WhisperFeatures.kt`, `WhisperOnnxEngine.kt`), because `onnx2ncnn` supports none of the quantized ops and the ncnn AAR expects a six-net decomposition HuggingFace does not export.+- **Speech-to-text** is `whisper-base` int8 ONNX (~77 MB) in `speech/src/main/assets/whisper-base/`, run on `onnxruntime-android` by `WhisperOnnxEngine.kt`. It replaced a 117 MB runtime download of the ncnn conversion from `data.vayunmathur.com/models/whisper-tiny/`. It was `whisper-tiny` until the swap to `base`, which roughly halves word error at the cost of about 36 MB of APK; the two exports declare identical operator sets, so the reduced ONNX Runtime build did not have to be regenerated. Upstream is **`onnx-community/whisper-base`** on HuggingFace (an ONNX Runtime dynamic quantization of `openai/whisper-base`, Apache-2.0), pinned to revision `1846881b` — a **build-host** dependency only, pinned by SHA-256 and refreshed by `scripts/speech/fetch_whisper_onnx.sh`. If it vanished, shipped builds keep transcribing. Note this moved the log-mel front end and the KV-cached decode loop into Kotlin (`WhisperFeatures.kt`, `WhisperOnnxEngine.kt`), because `onnx2ncnn` supports none of the quantized ops and the ncnn AAR expects a six-net decomposition HuggingFace does not export. - **Text-to-speech** voices all remain SHA-256-pinned downloads from `data.vayunmathur.com/models/piper/` (29 languages, 28–80 MB each). Bundling the English one was considered and dropped: at 51 MB it was 40% of the APK, and the ncnn `Vits` is filesystem-only so it would also have cost a second 51 MB extracted copy on disk. So a clean install transcribes with no network, but speaking still needs one voice download.@@ -140,7 +140,7 @@ Summed old per-crate locks (before workspace) = 712 total (641 excluding voxels) | `org.brotli:dec` | `0.1.2` | `extractor` | Google JVM port, low activity | `libs.versions.toml:9` | | `org.maplibre.compose:maplibre-compose` | `0.13.0` → `libmaplibre.so` native | `maps`, `weather`, `findfamily`, `photos` | Community-maintained FOSS renderer, better than Mapbox but smaller than Google Maps | `libs.versions.toml:78` | | `com.google.mediapipe:tasks-vision` | `0.10.35` (unified) | `camera` (face), vision segmentation | Native lib size; inline `0.10.14` drift resolved | `camera/build.gradle.kts:124`, `libs.versions.toml` |-| `com.microsoft.onnxruntime:onnxruntime-android` | `1.27.0` | `openassistant` (SigLIP), `speech` (whisper-tiny int8), `photos` (TinyCLIP int8) | MIT, Microsoft-maintained, low risk but native `.so` (~27 MB arm64, 35% of the `speech` APK). The reduced `onnxruntime-mobile` package is not usable: it lacks `ConvInteger`, which whisper's quantized Conv1d stem needs, and its last release was 1.18.0 in May 2024 | `openassistant/build.gradle.kts`, `speech/build.gradle.kts`, `photos/build.gradle.kts`, `libs.versions.toml:85` |+| `com.microsoft.onnxruntime:onnxruntime-android` | `1.27.0` | `openassistant` (SigLIP), `speech` (whisper-base int8), `photos` (TinyCLIP int8) | MIT, Microsoft-maintained, low risk but native `.so` (~27 MB arm64, 35% of the `speech` APK). The reduced `onnxruntime-mobile` package is not usable: it lacks `ConvInteger`, which whisper's quantized Conv1d stem needs, and its last release was 1.18.0 in May 2024 | `openassistant/build.gradle.kts`, `speech/build.gradle.kts`, `photos/build.gradle.kts`, `libs.versions.toml:85` | | `net.zetetic:sqlcipher-android` | `4.18.0` | `library:room` → `passwords`, `notes` | Small company, adds ~2MB `.so`, encrypted DB. `4.18.0` is the first release with `SQLCipherDriver` (an `androidx.sqlite.SQLiteDriver`), which is what lets encrypted databases work on Room 3 at all: Room 3 removed `openHelperFactory(...)` | `library/room/build.gradle.kts`, `libs.versions.toml:117` | | `io.coil-kt:coil-compose` + `coil-svg` + `coil-video` | `2.7.0` | `photos`, `maps`, `email`, `travel`, `education`, `pdf` | <3 maintainers, but widely adopted image loader | `libs.versions.toml:50` | | `org.bouncycastle:bcprov-jdk18on` + `bcpkix-jdk18on` | `1.85` | `pdf`, `passwords`, `messages`, `e2ee-p2p` | Small org, long-lived, well-audited PQC ML-KEM/ML-DSA; resource conflicts handled in `common-conventions-app` | `libs.versions.toml:84,226` |
gradle/libs.versions.toml
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 4702c0d777..f583a54906 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -294,7 +294,7 @@ jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit" } # On-device AI onnxruntime-android = { module = "com.microsoft.onnxruntime:onnxruntime-android", version.ref = "onnxruntimeAndroid" } # Same source as onnxruntime-android, built with --include_ops_by_config for exactly the-# operators whisper-tiny (speech) and TinyCLIP (photos) need: 10 MB of native code instead of+# operators whisper-base (speech) and TinyCLIP (photos) need: 10 MB of native code instead of # 28 MB. Only those two apps may use it — a model with an operator outside the configured set # fails at session creation, not at inference. openassistant stays on the full build. onnxruntime-reduced = { module = "io.github.vayun-mathur:onnxruntime-reduced-android", version.ref = "onnxruntimeReduced" }
scripts/speech/fetch_whisper_onnx.sh
diff --git a/scripts/speech/fetch_whisper_onnx.sh b/scripts/speech/fetch_whisper_onnx.shindex 7fc0223c37..16853dac33 100644--- a/scripts/speech/fetch_whisper_onnx.sh+++ b/scripts/speech/fetch_whisper_onnx.sh@@ -1,17 +1,17 @@ #!/usr/bin/env bash #-# Refresh the bundled Whisper-tiny int8 ONNX assets in speech/src/main/assets/whisper-tiny/.+# Refresh the bundled Whisper-base int8 ONNX assets in speech/src/main/assets/whisper-base/. # # Unlike the Piper voices, these are NOT downloaded at runtime — they ship inside the APK and # are read straight out of the asset manager by WhisperOnnxEngine, so this script is a # build-host tool for updating a vendored dependency, not a mirror-staging step. #-# Upstream is HuggingFace onnx-community/whisper-tiny, which is an ONNX Runtime *dynamic*-# int8 quantization of openai/whisper-tiny. We consume it as-is: onnx2ncnn cannot read+# Upstream is HuggingFace onnx-community/whisper-base, which is an ONNX Runtime *dynamic*+# int8 quantization of openai/whisper-base. We consume it as-is: onnx2ncnn cannot read # DynamicQuantizeLinear/MatMulInteger/ConvInteger, so there is no ncnn conversion path. # # The four files below are the whole runtime surface:-# encoder_model_int8.onnx audio -> 1500x384 hidden states+# encoder_model_int8.onnx audio -> 1500x512 hidden states # decoder_model_merged_int8.onnx KV-cached greedy decode (use_cache_branch switches) # vocab.json id -> token, for byte-level decode (no merges: decode only) # generation_config.json lang_to_id, suppress_tokens, special ids@@ -25,15 +25,17 @@ # set -euo pipefail -REPO="onnx-community/whisper-tiny"-REVISION="main"+REPO="onnx-community/whisper-base"+# Pinned, as the PP-OCR and Piper fetchers are: `main` moving under us would change the+# weights without changing this script.+REVISION="1846881b6b3a3024392c1eea3ad983695bc23925" BASE="https://huggingface.co/${REPO}/resolve/${REVISION}"-DEST="speech/src/main/assets/whisper-tiny"+DEST="speech/src/main/assets/whisper-base" # path-at-upstream sha256 FILES=(- "onnx/encoder_model_int8.onnx 03ff3c99ce804f79a42afd6212c9492eb75e55625926de66f8fc192e9567d336"- "onnx/decoder_model_merged_int8.onnx 25e807a962b6349356d0ea5d0dfe530b7e5bf0e2a484aeca0359d03143faddd3"+ "onnx/encoder_model_int8.onnx ca6177401f86a2c6b4dc5f7fc02fbca680678906bd0c22f6d89f0b80f124253f"+ "onnx/decoder_model_merged_int8.onnx fa3ef9902734ce5ae6f9ef2bdb2ba9a6c4b5785b09f4f420ce036573dc9d090b" "vocab.json 50d6a919f0a0601d56a04eb583c780d18553aa388254ba3158eb6a00f13e2c1a" "generation_config.json f5c67e5a4f7102f8cb4d058bc95da276bbc19eeec997267c3bb0f25ef68facd1" )
speech/build.gradle.kts
diff --git a/speech/build.gradle.kts b/speech/build.gradle.ktsindex 40f4623795..6789bbb293 100644--- a/speech/build.gradle.kts+++ b/speech/build.gradle.kts@@ -33,7 +33,7 @@ dependencies { // bin search and a quadratic solve per phoneme. Voices are extracted to disk before use. implementation(project(":library:ml")) - // Speech-to-text is whisper-tiny int8 ONNX (bundled in assets, see WhisperOnnxEngine).+ // Speech-to-text is whisper-base int8 ONNX (bundled in assets, see WhisperOnnxEngine). // It is not ncnn: onnx2ncnn has no DynamicQuantizeLinear/MatMulInteger/ConvInteger // support, and the AAR's Whisper expects a six-net decomposition HF does not export. //
speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnx
diff --git a/speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnx b/speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnxnew file mode 100644index 0000000000..abbe80534fBinary files /dev/null and b/speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnx differ
speech/src/main/assets/whisper-base/encoder_model_int8.onnx
diff --git a/speech/src/main/assets/whisper-tiny/decoder_model_merged_int8.onnx b/speech/src/main/assets/whisper-base/encoder_model_int8.onnxsimilarity index 61%rename from speech/src/main/assets/whisper-tiny/decoder_model_merged_int8.onnxrename to speech/src/main/assets/whisper-base/encoder_model_int8.onnxindex b43a8a2230..2738b5f948 100644Binary files a/speech/src/main/assets/whisper-tiny/decoder_model_merged_int8.onnx and b/speech/src/main/assets/whisper-base/encoder_model_int8.onnx differ
speech/src/main/assets/whisper-base/generation_config.json
diff --git a/speech/src/main/assets/whisper-tiny/generation_config.json b/speech/src/main/assets/whisper-base/generation_config.jsonsimilarity index 96%rename from speech/src/main/assets/whisper-tiny/generation_config.jsonrename to speech/src/main/assets/whisper-base/generation_config.jsonindex 3f732b9ea0..a57cdbf036 100644--- a/speech/src/main/assets/whisper-tiny/generation_config.json+++ b/speech/src/main/assets/whisper-base/generation_config.json@@ -1,28 +1,36 @@ { "alignment_heads": [- [- 2,- 2- ], [ 3,- 0+ 1 ], [- 3,+ 4, 2 ], [- 3,+ 4, 3 ], [- 3,+ 4,+ 7+ ],+ [+ 5,+ 1+ ],+ [+ 5,+ 2+ ],+ [+ 5, 4 ], [- 3,- 5+ 5,+ 6 ] ], "begin_suppress_tokens": [
speech/src/main/assets/whisper-base/vocab.json
diff --git a/speech/src/main/assets/whisper-tiny/vocab.json b/speech/src/main/assets/whisper-base/vocab.jsonsimilarity index 100%rename from speech/src/main/assets/whisper-tiny/vocab.jsonrename to speech/src/main/assets/whisper-base/vocab.json
speech/src/main/assets/whisper-tiny/encoder_model_int8.onnx
diff --git a/speech/src/main/assets/whisper-tiny/encoder_model_int8.onnx b/speech/src/main/assets/whisper-tiny/encoder_model_int8.onnxdeleted file mode 100644index e3cf1bbeaf..0000000000Binary files a/speech/src/main/assets/whisper-tiny/encoder_model_int8.onnx and /dev/null differ
speech/src/main/java/com/vayunmathur/speech/util/WhisperModel.kt
diff --git a/speech/src/main/java/com/vayunmathur/speech/util/WhisperModel.kt b/speech/src/main/java/com/vayunmathur/speech/util/WhisperModel.ktindex 6964793439..04e9786ff6 100644--- a/speech/src/main/java/com/vayunmathur/speech/util/WhisperModel.kt+++ b/speech/src/main/java/com/vayunmathur/speech/util/WhisperModel.kt@@ -3,7 +3,7 @@ package com.vayunmathur.speech.util import android.content.Context /**- * Asset location of the offline **Whisper-tiny** (multilingual, ~99 languages) recogniser.+ * Asset location of the offline **Whisper-base** (multilingual, ~99 languages) recogniser. * * These files used to be a 117 MB runtime download of the ncnn conversion. They are now the int8 * ONNX export bundled in the APK under `assets/`[DIR] and read by [WhisperOnnxEngine], so there@@ -11,7 +11,7 @@ import android.content.Context * `scripts/speech/fetch_whisper_onnx.sh` for how the vendored copies are refreshed. */ object WhisperModel {- const val DIR = "whisper-tiny"+ const val DIR = "whisper-base" /** * True if the bundled models are readable. Barring a corrupt install this is always true;
speech/src/main/java/com/vayunmathur/speech/util/WhisperOnnxEngine.kt
diff --git a/speech/src/main/java/com/vayunmathur/speech/util/WhisperOnnxEngine.kt b/speech/src/main/java/com/vayunmathur/speech/util/WhisperOnnxEngine.ktindex e9e76d8bef..5500f43ac7 100644--- a/speech/src/main/java/com/vayunmathur/speech/util/WhisperOnnxEngine.kt+++ b/speech/src/main/java/com/vayunmathur/speech/util/WhisperOnnxEngine.kt@@ -10,8 +10,8 @@ import java.nio.LongBuffer import org.json.JSONObject /**- * Offline **whisper-tiny** speech recognition on ONNX Runtime, reading the int8 models straight- * out of the APK's assets (see `speech/src/main/assets/whisper-tiny/`, refreshed by+ * Offline **whisper-base** speech recognition on ONNX Runtime, reading the int8 models straight+ * out of the APK's assets (see `speech/src/main/assets/whisper-base/`, refreshed by * `scripts/speech/fetch_whisper_onnx.sh`). * * Replaces the old ncnn `Whisper` AAR path, which needed a 117 MB runtime download. `onnx2ncnn`@@ -76,7 +76,7 @@ class WhisperOnnxEngine(private val context: Context) { if (loadFailed) return false return try { val opts = OrtSession.SessionOptions().apply {- // Whisper-tiny is small; two threads is a reasonable latency/battery balance.+ // Whisper-base is still small; two threads is a reasonable latency/battery balance. setIntraOpNumThreads(2) setInterOpNumThreads(1) }@@ -327,14 +327,18 @@ class WhisperOnnxEngine(private val context: Context) { private companion object { const val TAG = "WhisperOnnxEngine" - const val DIR = "whisper-tiny"+ const val DIR = "whisper-base" const val ENCODER = "encoder_model_int8.onnx" const val DECODER = "decoder_model_merged_int8.onnx" const val VOCAB = "vocab.json" const val GEN_CONFIG = "generation_config.json" - const val N_LAYERS = 4- const val N_HEADS = 6L+ // whisper-base: 6 encoder and 6 decoder layers, 8 heads of 64. These size the KV cache+ // buffers below, so a stale value does not fail cleanly - it feeds the session a+ // wrong-shaped past and the decode wanders. Read from the export''s config.json:+ // d_model 512, encoder_layers 6, decoder_layers 6, attention heads 8.+ const val N_LAYERS = 6+ const val N_HEADS = 8L const val HEAD_DIM = 64L /** One 30 s window cannot say more than this; guards against a runaway loop. */