Most modern text-to-speech audiobook apps rely on cloud APIs. They stream audio from remote servers, require accounts, upload private EPUBs and study PDFs to third-party infrastructure, cap monthly hours, and stop working the second you board a flight or enter a subway.

While building Lector (app.lectorreader.audiobook), an offline Android e-book and audiobook reader in Flutter, I set one strict architectural constraint from day one: zero cloud TTS or LLM calls, ever. Every voice, translation, and text-cleanup pass has to run 100% locally on everyday Android hardware.

In our v1.2.5 release, we shipped 25 downloadable neural voices across 11 languages by running two complementary sherpa-onnx backends side by side: Supertonic 3 INT8 (44.1 kHz) and Piper VITS (22.05 kHz).

Along the way, physical Hardware-in-the-Loop (HIL) testing on a mid-range $180 Redmi Note 13 (Snapdragon 685, 8-core ARMv8, Android 14) caught real-world bottlenecks that unit tests and emulators completely missed. Here are the exact benchmarks and four engineering lessons we learned.

1. Real Hardware Benchmarks (Snapdragon 685, Airplane Mode)

Instead of forcing one neural TTS architecture onto every phone, we pair two local engines through sherpa-onnx:

Engine Model Architecture Sample Rate Pack Size Voices / Languages Snapdragon 685 RTF Sweet Spot
Fast Offline AI Piper VITS (csukuangfj/vits-piper-*) 22.05 kHz ~18-65 MB / voice 15 voices / 7 languages (EN, ES, DE, FR, PT, RU, KK) 0.29 - 0.33 (3x faster than real-time) Budget CPUs, long commutes, E-ink battery life
Studio HD Supertonic 3 INT8 (numSteps = 5) 44.1 kHz ~123 MB shared pack 10 multilingual voices / 10 languages (EN, ES, DE, FR, PT, IT, PL, TR, UK, RU) 1.06 - 1.20 on budget SD685; < 0.50 on mid/flagship SoCs Expressive audiobook narration, multi-voice dialogue duets, offline 44.1 kHz .m4a/.wav export
System Fallback Android Local TTS System 0 MB 11 languages < 0.10 Instant zero-download fallback

RTF (Real-Time Factor) = synthesis time / audio duration. Values below 1.0 run faster than real-time playback.

2. Lesson #1: Never Silently Degrade Voice Quality to Hide Slow CPUs

On a flagship Snapdragon 8 Gen 2/3, Supertonic 3 INT8 at numSteps = 5 flies well below RTF 0.50. On our budget Snapdragon 685 test phone, however, sustained synthesis hovered around RTF 1.06 - 1.20.

Our first instinct was clever-on-paper: build an adaptive RTF governor that automatically steps diffusion down (5 -> 3 -> 2 steps) whenever a slow CPU falls behind real-time playback.

Then we actually recorded the device audio and listened to it on headphones.

Below 5 steps, Supertonic 3 immediately picked up noticeable metallic artifacts and flattened prosody. Users would not think "my CPU is slow", they would think "these Studio HD voices sound robotic."

So we reverted step-down permanently and locked numSteps = 5 as a hard quality floor for live playback (8 steps for Max Quality .m4a / .wav offline export). To make playback feel snappy without ruining voice fidelity, we combined three things:

  1. Short first micro-chunk so time-to-first-audio stays fast.
  2. 4-level priority prefetch queue inside the isolate worker pool (prioritizing the active playback cursor over lookahead chunks).
  3. Honest hardware guidance: if the governor observes RTF > 1.02 across two consecutive chunks (>= 1.2s), it surfaces a single polite hint recommending our Fast (Piper) voices (RTF ~0.30) instead of silently degrading audio.

3. Lesson #2: Mutual RAM Eviction (-157 MB Peak RSS)

Android's Low Memory Killer (LMK) is unforgiving on 4 GB devices when an app plays background audio with the screen locked.

Holding both a warm Supertonic 3 ONNX session and a warm Piper ONNX session in native RAM at the same time pushed peak RSS dangerously close to background eviction when users switched voices mid-book.

The fix was straightforward and measurable: enforce strict mutual engine eviction in our native worker coordinator. Whenever the user activates a Supertonic 3 voice, any resident Piper session is cleanly torn down and freed (and vice versa). That single architectural invariant cut peak native RAM overhead by ~157 MB, stabilizing background playback across 4 GB phones.

4. Lesson #3: Fixing a 37.3s System ANR on Long Justified Chapters

Unit tests usually feed parsers 200-character mock strings. Real books are different.

When we tested a full 40,000+-character chapter (The Adventures of Sherlock Holmes) on physical hardware with three popular typography features turned on simultaneously:

  • Full justification (TextAlign.justify)
  • Automatic visible syllable hyphenation (-)
  • Bold Word Starts (bionic reading)

...the eager paragraph pre-pass blocked the UI isolate for 37.3 seconds, triggering a hard Android System ANR.

We replaced the eager layout pass with an incremental frame-budgeted controller (IncrementalVisibleHyphenController):

  • Frame 0 computes hyphenated spans only for the currently visible viewport within a strict 12 ms budget, so the book opens immediately.
  • Off-screen paragraphs fill in incrementally in 6 ms frame-aligned slices while the user reads or listens.

Measured on the exact same Redmi Note 13 with Justify=ON + Bionic=ON:

  • Cold book open: 37.3s ANR -> 3.86s (0 ANR)
  • Chapter switch: 1.31s
  • Smooth 120 FPS word-by-word karaoke highlighting with zero dropped frames.

5. Lesson #4: Linear O(N) PDF Cleanup & 1:1 Offline Bilingual Subtitles

Two smaller production lessons that made a huge UX difference:

  • Linear O(N) PDF reflow: Real 80-page study PDFs broke naive regex-based line-wrap cleaners and hung progress bars at 88%. Refactoring PdfTextCleaner to single-pass linear O(N) with explicit numbered-heading preservation (3. Section Title) and honest two-phase progress (0-85% extraction, 85-100% cleanup & save) eliminated stalls.
  • Single source of truth for 1:1 Live Bilingual Subtitles: Our 59-language offline translator lets language learners display translated sentence subtitles above the mini-player while listening. Initially, subtitle text drifted one sentence ahead of the reader's highlight because it subscribed to synthesis chunks instead of the active playback cursor. Binding the subtitle bar directly to the exact same highlightedSentenceSpanListenable that drives the text spotlight gave locked 1:1 parity.

Full Benchmarks & Links

If you are building offline mobile AI or Flutter audio apps and want to inspect the full benchmark notes or test the app directly:

Happy to answer any questions in the comments about Flutter + sherpa_onnx isolate pools, acoustic boundary timing for word-level highlighting, or Android MediaCodec .m4a batch export!