Skip to content

feat: LiteRT engine consolidation + on-device STT (flutter_gemma_speech, moonshine)#389

Open
DenisovAV wants to merge 20 commits into
mainfrom
feat/litert-base-speech
Open

feat: LiteRT engine consolidation + on-device STT (flutter_gemma_speech, moonshine)#389
DenisovAV wants to merge 20 commits into
mainfrom
feat/litert-base-speech

Conversation

@DenisovAV

Copy link
Copy Markdown
Owner

Summary

Consolidates the shared LiteRT runtime into flutter_gemma_litertlm (now the full LiteRT engine) and adds on-device Speech-to-Text via a new flutter_gemma_speech package. First STT model: moonshine-tiny (raw PCM, no mel frontend). The model is selectable like inference models (SttModelType on the spec) — one generic backend + recognizer driven by a per-model profile.

Phase 1 — engine consolidation + core STT contracts

  • flutter_gemma_litertlm absorbs the LiteRt interpreter FFI (LiteRtBindings, moved in from embeddings) and the web litert.js/tensorflow.js runtime (moved in from core) → it is now the sole owner of libLiteRtLm; the stale-owner coordination marker is retired.
  • flutter_gemma_embeddings becomes thin logic depending on litertlm (drops its own hook + FFI + engine web JS). Public API (LiteRtEmbeddingBackend) unchanged.
  • flutter_gemma (core) loses the engine web JS → truly engine-free.
  • Core STT contracts (runtime-agnostic, mirror the embedding probe-chain): ModelManagementType.stt, SttModelSpec + SttModelType, SttBackendProvider/SttRegistry, SpeechRecognizer, FlutterGemma.initialize(sttBackends:), installStt()/getActiveStt() + createSttModel dispatch (mobile/web/desktop) + active-model persistence.

Phase 2 — flutter_gemma_speech (STT, moonshine)

  • New package depends on core + litertlm (shared libLiteRtLm, no own hook).
  • LiteRtSttBackend (sole .tflite STT backend; canHandle => true; returns the core SpeechRecognizer interface). Concrete pipeline (LiteRtSpeechRecognizer, SttModelProfile, SttWorker, SttCore, HfTokenizer) is internal to lib/src/, not exported.
  • Generic pipeline: raw-PCM → encode → autoregressive greedy decode → HF-tokenizer detokenize, driven by SttModelProfile.forType(sttModelType). moonshine profile filled; whisper/parakeet (log-mel) arms throw UnimplementedError (follow-on).
  • Example: STT model catalog + selection screen + transcribe screen.

Validation (on-device, macOS)

  • Phase 1: standard desktop_embedding_test green — embeddings still produce a 768-dim vector through the moved FFI on libLiteRtLm 0.14.0.
  • Phase 2: end-to-end through the public API (installSttgetActiveStttranscribe) transcribes a known clip → "Ever tried ever failed, no matter."

Follow-ups (not in this PR)

  • A committed on-device STT integration test (validated here via a throwaway harness).
  • A mobile-platform gate (iOS/Android) for STT + the consolidated embeddings.
  • Hook robustness: invalidate/refresh the in-repo native prebuilt when the pinned native version changes (a stale local prebuilt silently runs the old libLiteRtLm after a version bump).
  • whisper/parakeet profiles (need a Dart log-mel frontend); streaming STT; STT web arm; TTS + voice loop.

DenisovAV added 20 commits July 23, 2026 11:51
Expose LiteRtBindings via a public native-only litertlm/lib/litert_bindings.dart
(avoids an implementation_imports lint on embeddings' native-only file), plus
trivial prefer_initializing_formals / unnecessary_library_name fixes so
flutter_gemma_embeddings analyzes clean again.
…r-path leak, NaN decode diagnostic, hiddenBufPtr leak, unlock status checks
…core to 1.4.0 (+CHANGELOG); speech requires flutter_gemma ^1.4.0
…repo.ModelType.stt (was silently bucketed into embedding in getInstalledModels/isAnyModelInstalled)
…dow (unconditional in-progress completer guard, mirrors desktop)
… the consolidated single-hook engine + wired moonshine STT
…port-leak guard, drop dead crypto dep, fix path-import shadow, RuntimeConfig.tokenizerPath doc, stt_screen reentrancy guards
…twork install + bundled clip via public API)
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