DEV Community

Cover image for Two speech models, one APK, no network: what broke running Granite and Nemotron offline on Android
Ahmed Ibrahim
Ahmed Ibrahim

Posted on

Two speech models, one APK, no network: what broke running Granite and Nemotron offline on Android

VoxScribe is a free, open source (MIT) voice typing app. On Android it puts a small button above your keyboard in any app: hold it, talk, and the words are typed where your cursor is. Speech recognition runs on the phone, so it works in airplane mode and the audio never leaves the device.

Until version 1.2.0 the Android app used Whisper. Version 1.2.0 replaces it with two newer open models:

  • IBM Granite Speech 5.0 470M TurboCTC (Apache 2.0) for English, French, Spanish, German, Italian and Portuguese. About 536 MB as int8 ONNX.
  • NVIDIA Nemotron 3.5 ASR Streaming 0.6B (OpenMDW 1.1) for 15 more languages, including Arabic, Hindi, Japanese, Korean, Chinese, Russian and Turkish. About 682 MB, the int8 export from sherpa-onnx.

The swap was worth it. On a set of real, accented English recordings, Granite made 18.8% word errors, against 34.9% for Whisper Base and 24.5% for Whisper Small. It decodes an 8 second phrase in under half a second on a mid-range phone, and Nemotron does a 7 second phrase in about a second.

Getting there was less smooth. Here is what broke.

1. Two copies of onnxruntime, one file name

Granite runs through Microsoft's onnxruntime-android (1.28.0). Nemotron runs through sherpa-onnx (2.0.2), which brings its own libonnxruntime.so, version 1.28.2. An APK can only hold one file called libonnxruntime.so, so Gradle keeps one and drops the other.

That sounds harmless, since both are almost the same version. It is not. Every exported function in these libraries carries a version label (VERS_1.28.0 or VERS_1.28.2), and the dynamic linker checks it. Whichever copy is dropped, the other side fails at load time:

cannot locate symbol "OrtGetApiBase"
Enter fullscreen mode Exit fullscreen mode

The fix keeps sherpa's newer 1.28.2 library and points onnxruntime's small Java bridge (libonnxruntime4j_jni.so) at it. The bridge's ELF file asks for VERS_1.28.0 in its version-needs section, so a short Python script rewrites that request to VERS_1.28.2 and repacks the AAR:

OLD = b"VERS_1.28.0"
NEW = b"VERS_1.28.2"

def relabel(so: bytes) -> bytes:
    data = bytearray(so)
    # find the SHT_GNU_verneed section (type 0x6FFFFFFE),
    # rewrite the version name and its ELF hash
    ...
Enter fullscreen mode Exit fullscreen mode

Renaming the string is not enough: each entry also stores the ELF hash of the version name, so the script recomputes it. This only works because the bridge needs just three functions (OrtGetApiBase and two execution provider calls), both libraries export them, and 1.28.2 still serves API version 28, the one the 1.28.0 bridge asks for. The APK is arm64 only, so only that one bridge is patched.

If you combine sherpa-onnx with plain onnxruntime in one Android app, expect to hit this.

2. Porting the feature extractor by hand

sherpa-onnx handles Nemotron end to end, including the audio front end. Granite had no Android runtime, only the ONNX graph, so the log-mel front end had to be written in Kotlin: an HTK mel filter bank, power spectrum with centred reflect padding, log10 floored 8 below the clip's peak, deltas, and two frames stacked into each 320-value input.

It was ported line by line from the model's own Python feature extractor and compared on real clips until the outputs matched to within 0.00004. Small differences here don't crash anything. They just quietly raise the error rate, which is worse, because nothing tells you.

Long recordings (file imports) go through the model in 30 second pieces, each starting at the quietest spot near the boundary, so the output never needs gigabytes of memory.

3. The stray Japanese letter

Granite's vocabulary includes pieces from other scripts. On an unclear sound it sometimes emitted one, and a dictated English word came out as Sendデ.

Every language Granite types in the app is written in Latin letters, so letters from any other script are now dropped. Digits, punctuation and symbols stay:

fun latinOnly(text: String): String {
    if (text.all { it.code < 0x250 }) return text  // fast path
    val out = StringBuilder()
    var i = 0
    while (i < text.length) {
        val cp = text.codePointAt(i)
        val keep = !Character.isLetter(cp) ||
            Character.UnicodeScript.of(cp) == Character.UnicodeScript.LATIN
        if (keep) out.appendCodePoint(cp)
        i += Character.charCount(cp)
    }
    return out.toString().replace(Regex(" {2,}"), " ").trim()
}
Enter fullscreen mode Exit fullscreen mode

4. Cutting audio at every breath broke sentences

Importing an audio or video file splits it at pauses, and each piece goes through the model on its own. The first version cut at every short pause. The model then never saw a sentence whole, and the words at each cut suffered:

"EBITDA grew and the free cash flow" came out as "grow and. Free cash flow"

The segmenter now keeps pieces long. A piece ends at a long pause (1.2 s) once it is a second long, at a short pause (0.4 s) only once it reaches 8 seconds, and at the quietest moment of its last few seconds when it hits 20 seconds. Silence between pieces is dropped, which also stops the model from inventing text for it.

5. Picking languages by testing, not by the model card

Nemotron's model card lists more languages than the app ships. Each candidate was checked on synthetic test speech before it was added. Swedish, Danish, Norwegian, Romanian, Bulgarian, Croatian and Estonian came in at 18 to 67% word errors and were left out. Turkish went to Nemotron, because Granite could not type it at all.

The app also tells people what it can't do yet. If the model for your language isn't downloaded, the button says so instead of falling back to a weaker recognizer. Earlier versions could fall back to Google's recognizer. 1.2.0 removed that, so there is now exactly one path for your audio, and it stays on the phone.

6. Shipping 1.2 GB of models without bloating the APK

The APK is about 26 MB. The models are downloaded once, in setup, from a GitHub release. Every file has a known size and SHA-256 checked before it is used. Downloads go to a .part file first, so a failed or cancelled download leaves nothing half-written, and files that already match are skipped on a retry.

Try it

The APK and the source are on GitHub: VoxScribe releases. There's also a Windows version with the same idea: hold a key, talk, and it types.

If you speak one of the 21 languages, which words does it get wrong for you? That's the most useful feedback for deciding what to fix next.

Disclosure: most of the app's code was written with Claude Code, an AI coding assistant, and tested by hand on real phones. The speech models are IBM's and NVIDIA's.

Top comments (4)

Collapse
 
userxnom profile image
Abdullah Naseer •

The libonnxruntime.so collision is the part that would have caught me out — two libraries at 1.28.0 and 1.28.2, one filename, and a linker that refuses to be reasonable about it. Relabeling VERS_1.28.0 to VERS_1.28.2 and recomputing the ELF hash is a neat, honest fix. I also liked the segmentation change: keeping pieces long and only cutting at a 1.2s pause makes sense once you see "EBITDA grew and the free cash flow" come out as "grow and. Free cash flow". Did the longer segments cost you much latency on low-end devices, or does the 30-second chunking keep that in check?

Collapse
 
ahmed_ibrahim_1994 profile image
Ahmed Ibrahim •

The longer pieces only apply to file imports, so live dictation never waits on them. When you hold the button, the whole clip goes to the model in one pass, and most of those are a few seconds long.
For imports, the total work barely changes: the same minutes of audio get transcribed either way, just in fewer, longer pieces. What changes is the gap before the first text shows up, since a piece can now run up to 20 seconds before it’s handed over. That’s fine for a file, because the screen shows progress through the whole import rather than streaming words.
The 30 second chunking inside the Granite engine is a separate safety net. The segmenter already caps pieces at 20 seconds, so in practice it only matters if something longer gets through. Its job is keeping the model’s output memory bounded, which is what actually breaks on low-RAM phones, more than speed.
On a mid-range phone Granite does an 8 second phrase in under half a second, so a 20 second piece is still about a second of work. I don’t have clean numbers from truly low-end devices yet. If you try it on one, I’d like to hear how it does.

Collapse
 
prikshit profile image
Prikshit •

The load failure is the part I'd remember: both libraries ship libonnxruntime.so, Gradle keeps one, and the other side dies with a missing OrtGetApiBase because the ELF version label still asks for 1.28.0. Rewriting that request to 1.28.2 is a fragile fix, but it is honest about what the linker actually checks. Downloading the models after install with a SHA-256 check, and writing to a .part file first, is the right way to keep a 26 MB APK from shipping 1.2 GB of weights.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

rewriting VERS_1.28.0 to 1.28.2 and then the hash on top of it. that is the part most writeups would skip.