Skip to main content

Offline speech-to-text for Flutter, with no server and no API key

Live, hands-free transcription on iOS and Android, entirely on the phone

Updated 5 min readMarkdown
Offline speech-to-text for Flutter, with no server and no API key

At work I build real-time transcription with cloud speech APIs. They are very good. They also need a network connection, an account, a key, a bill, and a decision about whose servers your users' voices go to.

I wanted to know how close a phone could get on its own. So I built transcribe_cpp, a Flutter package that turns speech into text entirely on the device, on iOS and Android. The user talks, your app gets text, and the audio never leaves the phone.

It started as an experiment and a way to learn. It is now on pub.dev, MIT licensed, and the code is on GitHub.

What it does

  • Private. No server, no account, no API key. It works in airplane mode.

  • Hands-free. There is no button to hold. Voice detection decides when each sentence starts and ends.

  • Live text. Words appear while the person is still talking, and settle in place without flickering.

  • Fast. On a mid-range phone, the recommended model transcribes speech about 40 times faster than real time.

  • Survives real life. Phone calls, Siri, headphones plugged in or pulled out, the screen locking, the app going to the background.

  • Bring your own audio. If your app already records, hand the audio over at any sample rate and skip the microphone handling entirely.

Using it

flutter pub add transcribe_cpp
import 'package:transcribe_cpp/transcribe_cpp.dart';

// Download a model once (90 MB). Later calls return it straight away.
final models = await ModelManager.open();
final model = await models.ensure(const ModelId('parakeet-tdt_ctc-110m-Q4_K_M'));

// Load it, and listen.
final session = await TranscribeSession.open(model);
await session.start();

// Show the text as the user speaks.
ValueListenableBuilder(
  valueListenable: session.text,
  builder: (context, text, _) => Text(text.full),
);

await session.stop();

That is the whole thing. Add a microphone permission to Info.plist and the Android manifest, and you have live dictation.

If you already capture audio yourself, from a call, a file or your own recorder:

await session.transcribeStream(
  myAudio,
  format: const AudioFormat(sampleRate: 48000),
);

Standing on transcribe.cpp

I did not write a speech recognizer. The models run on transcribe.cpp, a C++ engine built on ggml, the library behind llama.cpp and whisper.cpp. It runs a whole catalogue of open speech models, converts them, and publishes their accuracy.

transcribe_cpp is the part between that engine and a Flutter app: the microphone, deciding when someone is speaking, splitting speech into sentences, live text, and staying alive through everything a phone throws at a long recording.

The model I recommend is NVIDIA's Parakeet 110M: a 90 MB download with a 2.5% word error rate on the LibriSpeech benchmark. Models are downloaded when the app first needs them, so your app stays small; the package itself adds about 6 MB.

What turned out to be hard

Getting a model to produce text was the easy week. Everything around it took the time.

Live text that doesn't flicker. The models I use transcribe a whole sentence at once; they don't stream word by word. To show text while someone is still talking, the package re-reads the unfinished sentence every 350 ms. But the last word or two of each read is a guess, because the model hasn't heard what comes next yet. Show those guesses and the text jitters as words rewrite themselves. So a word only appears once two reads in a row agree on it. The text only grows, and it feels live.

Knowing when a sentence ends. With no button, something has to decide when you've finished speaking. Wait too long and the text feels slow; cut too early and you split sentences mid-thought, which costs accuracy. The package runs Silero VAD, a small voice-detection model I ported to plain C, and an endpointer tuned by measuring, not by feel. Most errors came from where sentences were cut, not from the recognition itself.

Phones interrupt you. iOS stops your audio for a phone call or Siri and tells you when you can have it back. Headphones change the microphone's sample rate under you. Android doesn't stop the recording at all when a call takes the microphone: it quietly feeds you silence. And iOS refuses GPU work from an app in the background, so when the screen locks, the package moves decoding to the CPU and back to the GPU when the app returns. Each of these needed its own handling, so a long session keeps going without the app babysitting it.

Two bugs every Flutter plugin author should know about. Since Flutter 3.29, Dart runs on the platform's main thread, so stopping the microphone froze my UI animations while the audio system shut down. And on iOS, release builds silently removed the C functions Dart calls through FFI, while debug builds hid the problem completely. Both will get their own posts.

Try it

The example app lets you browse the whole catalogue of 58 models, download a few, and switch between them on your own phone in a few minutes. That beats any number I could give you.

It is early. Android runs on the CPU for now, and Bluetooth headset microphones work on iOS but not yet on Android. If you try it, I'd like to hear how it goes: bug reports, questions and ideas are all welcome in GitHub Discussions or the issues.

Thanks to the transcribe.cpp authors, the ggml project, the Silero team, NVIDIA and the Moonshine team, whose work this is built on.

The audio never leaving the phone is a big deal for apps handling private stuff. Nice to see offline speech getting fast enough to feel usable on a normal phone.

Keeping the audio on the phone removes the whole question of whose servers the voice goes to, that alone makes on-device worth the accuracy tradeoff for a lot of apps. Getting live text to settle without flickering is harder than it looks.

Thanks! The flicker was the part that took the longest to get right. It’s surprising how much the last word of each read changes.

One edge case I’d be curious about is what happens when the audio route changes mid-session. For example, a user starts dictating through a Bluetooth headset, unplugs it halfway through a sentence, and the phone switches back to its built-in mic with a different sample rate.

On iOS, a route change can affect the sample rate and channel configuration, so it’s not just a microphone restart problem. How does transcribe_cpp handle that transition? Does it rebuild the capture pipeline while preserving the current utterance, or does it finalize the sentence and start a fresh one? That distinction matters quite a bit for hands-free transcription, especially during long sessions.

Great question, and you've found a real gap. On a route change (headset connected or removed, earbuds plugged in), iOS capture tears down the tap and the resampler and rebuilds them against the new input format, because AVAudioEngine won't pick up the new rate by itself. Capture keeps writing to the same ring buffer, so nothing downstream has to reconnect, and you can see the change as a short "recovering" state.

On the Dart side, audio on either side of the switch isn't continuous, so voice detection and the endpointer are reset rather than stitching two moments into one. Today that reset throws away the sentence that was in progress instead of finishing it. Whatever the user said before the switch is lost, and a new sentence starts on the new mic. Finishing it properly is the right behaviour: decode what was heard before the switch as a final result, then start fresh. That's the next fix.

One thing I’d be careful about here is the timing of the final decode. Say the Bluetooth input is running at 16 kHz mono, and the route switches to the built-in mic at 44.1 kHz while the decoder still has unprocessed frames from the previous utterance. If the VAD and endpointer reset immediately, how do you make sure those buffered frames are actually decoded before the old state is discarded?

I’d probably treat the route change as a boundary between two audio segments: stop accepting frames from the old capture session, drain its pending audio through the existing resampling and decode path, emit a final result if there’s enough speech to recover, and only then reset the endpointing state for the new input. Otherwise, even if the ring buffer survives the switch, the sentence can still disappear because the decoder never gets a chance to finish it.

There’s another edge case worth thinking about: what happens if a route change lands while the capture callback is still delivering buffers in the old format? For example, a Bluetooth headset disappears, the input switches to the built-in mic, and a delayed callback from the old tap arrives after the new resampler has been configured.

If both streams write into the same ring buffer, I’d want some explicit guarantee that frames from different input configurations can’t be interpreted using the wrong sample rate or channel layout. One approach would be to tag buffers with a capture-generation ID and format metadata, then reject stale callbacks while keeping the old segment available for final decoding. That would also make rapid headset connect/disconnect cycles easier to handle without accidentally mixing audio across route changes. Does the current capture layer already guard against that race, or is that something you’re planning to address alongside utterance preservation?

Fixed in 0.1.3, now on pub.dev. Testing it showed two problems, not one. On iOS, re-activating the audio session during the change was refused, so the mic could stop entirely; a route change now rebuilds only the engine. And the sentence in progress is now finished instead of dropped.

The order you describe is how it works now. The ring only ever holds 16 kHz mono, because each tap callback converts before it writes. So on a route change the audio already buffered from the old route is drained into the endpointer first, the open sentence is emitted as a final result and queued for the decoder, and only then is the endpointer reset for the new input. The decoder runs separately, so the reset can't cancel a decode that's already queued.

On stale callbacks: the old tap is removed and the engine stopped before the new converter is built, so a buffer in the old format shouldn't reach it. There's no explicit check, though, and checking each buffer's format against the converter's input is cheap, so I'll add one.

The "whose servers your users' voices go to" framing is exactly the decision point. I hit the same one with documents instead of voice - official letters people shouldn't upload anywhere - and ended up with a local model on CPU for the same reason you ended up on-device: the constraint turns out to be the feature. The 40x-real-time number on a mid-range phone kills the assumption that local always means slow. Curious about the voice detection part: did you have to tune it per language or per environment, or does the default hold up in noisy places?

Thank you! No per language tuning. Silero VAD does not report the language of the audio, only whether it is speech or not, so the same settings work for all languages. I ran long public recordings (earnings calls and podcasts) through the real pipeline with the defaults and they stood up to added noise. The tough case is when other people are talking in the background. That is speech, so the detector carries on. Steady noise like fans or traffic is okay. If your environment needs something different, then every threshold is in EndpointerConfig.

YYouBeyond24d ago

The two-read agreement rule raises an interesting boundary: what happens if a word agrees twice, then the completed sentence changes it? Does the final pass correct the displayed text, or is the committed prefix fixed? A small example with a long pause in the middle of a phrase would help distinguish stable display from final transcription accuracy.

Good question. The two answers are different on purpose. While you’re speaking, the live text only grows: once a word has matched across two reads it’s never removed, even if a later read changes its mind. That’s what keeps the live text from flickering. When the sentence ends, the whole utterance is decoded again in one pass, and that result replaces the live text completely. So if anything was wrong in the live text, the final result corrects it.

On the long pause: if you stop for more than about 400 ms, that counts as the end of the utterance. The first half gets its final result straight away, and the rest starts a new paragraph. A mid-phrase pause can therefore split a sentence in two, and the first half is decoded without the words that come after it. That’s the trade for getting text quickly. A longer hangover setting means fewer splits but a later final result.

Thanks for the detail. Background speech is exactly the case that bites in practice, and good to know the thresholds are all exposed in EndpointerConfig. I will take a look.

Thanks, let me know how it goes if you try it.