Skip to content

Repository files navigation

LiteRT-LM-Unity

Unity integration for on-device AI on Android. Runs LLM chat, speech recognition (ASR), image understanding and function calling entirely on the device, with no network.

  • LiteRT-LM v0.14.0 (.litertlm 1.5.0); customizations live in Tools/UnityAar/litert-lm-unity-aar.patch
  • Device-verified on Snapdragon 865 / 7.5 GB RAM / Android 12 — all four capabilities PASS across 6 PDCA cycles, 80+ runs, zero crashes (ledger)
  • Published models: whisper-acft · whisper-acft-ko · litert-lm-unity-quantized

Capabilities (measured on device)

Capability Speed Hit rate Model
LLM chat 35.5 tok/s Qwen2.5-0.5B i4
Speech recognition 0.7–0.8 s 4/5 whisper-base-acft-ko 5s
Image understanding 7.6 s (GPU) accurate gemma-4-E2B QAT
Function calling 15.5 s E2E (voice → tool) 19/20 gemma-4-E2B / Qwen3-0.6B

Requirements

Unity 2022.3 or newer (developed and device-verified on 6000.4.6f1) + Android Build Support · Android device (adb, Snapdragon 865 class or better, 4 GB+ RAM) · Windows PowerShell (build scripts) · Docker (only to rebuild the AAR)

Install

The runtime ships as a UPM package, com.leuconoe.litert-lm-unity. In Package Manager choose Add package from git URL… and paste:

https://github.com/Leuconoe/LiteRT-LM-Unity.git?path=/Packages/com.leuconoe.litert-lm-unity

Or add the line yourself to Packages/manifest.json:

{
  "dependencies": {
    "com.leuconoe.litert-lm-unity": "https://github.com/Leuconoe/LiteRT-LM-Unity.git?path=/Packages/com.leuconoe.litert-lm-unity"
  }
}

Pin a release by appending a tag: …litert-lm-unity#v0.14.0a-unity. Git URL installs need git on PATH; the package carries a 31 MB Android AAR, so the first resolve takes a moment.

Samples — in Package Manager select LiteRT-LM for UnitySamples:

Sample Contents
Test Scenes Seven hand-driven scenes (quick start, chat, ASR, multimodal, voice FC, multimodal FC, translate), the Android build menu and the scene generator
Automated Tests Three unattended scenes (Android smoke, conversation, FC benchmark) that run on load and write their results to Builds/Logs/

Import Test Scenes first; Automated Tests is only needed for regression runs.

Working in this repository instead of consuming the package? The samples live in Samples~/, which Unity does not compile. Import them once with:

.\Tools\Windows\Restore-LiteRtLmSamples.ps1

Quick Start

  1. Install the package and import the Test Scenes sample (above)
  2. Place models — pick from the tables below and put them under Assets/StreamingAssets/ (model files are not in the repository)
  3. Build the APK — Unity menu LiteRT-LM/Android/... or Tools/Windows/Tests/Build-LiteRtLmAndroid*.ps1
  4. Smoke testRun-LiteRtLmAndroidAsrSmokeTest.ps1 -DeviceSerial <serial>; results land in Builds/Logs/AndroidDeviceRuns/

Package layout

Path Contents
Packages/com.leuconoe.litert-lm-unity/Runtime/ LiteRtLmUnityClient (Android bridge), LiteRtLmMicVadCapture, LiteRtLmStatusHudOverlay, LiteRtLmWindowsCliClient, and the native AAR
Packages/com.leuconoe.litert-lm-unity/Samples~/TestScenes/ Scene runners, the seven hand-driven scenes, the APK build menu and the scene generator
Packages/com.leuconoe.litert-lm-unity/Samples~/AutomatedTests/ Smoke, conversation and function-calling benchmark scenes
Assets/StreamingAssets/ Where you place models (not in the repository)
Tools/Windows/ Build and workflow scripts · Bin/ prebuilt runtime · Tests/ device and smoke runners
Tools/Research/ Conversion and benchmark drivers behind the numbers in docs/
docs/ Benchmarks and handoffs

Recommended models

LLM — pick by device RAM

Device RAM Model Size Measured on device Download
4–6 GB LLM/qwen2.5-0.5b/…_wi4b64_ekv1280.litertlm 265 MB 35.5 tok/s — chat only (not usable as an FC router) project int4 (upstream f32)
6–8 GB LLM/qwen3-0.6b/qwen3_0_6b_mixed_int4.litertlm 475 MB 20.9 tok/s, FC 18/20 litert-community/Qwen3-0.6B
8 GB+ Multimodal/gemma-4-e2b/gemma-4-E2B-it.litertlm 2.6 GB FC 19/20, image 7.6 s, audio 4.1 s; image turns peak at 3.6 GB PSS litert-community/gemma-4-E2B-it-litert-lm

LFM2.5-1.2B int4 (702 MB, 16.8 tok/s, FC 17/20) is also available as a mid-size FC router. Use CPU for chat (decode) and GPU for long prompts and images. LLM details →

ASR — pick by utterance length (one model is usually enough)

Utterance length Model Size Measured on device Download
≤5 s (commands, short sentences) ASR/whisper-base-acft-ko/acft_base_5s_drq.tflite 101 MB 0.7–0.8 s, 4/5 exact leuconoe/whisper-acft-ko
5–30 s (dictation) ASR/whisper-base/whisper_base_30s_i8.tflite 77 MB 2.7 s, sentence CER 0.000 project i8 (upstream f32)
>30 s (batch) ASR/qwen3-asr-0.6b/qwen3_asr_0.6b_5s_i8.tflite 794 MB chunk loop, RTF ≈2.6 Qwen/Qwen3-ASR-0.6B

All 10 tiers, selection rationale, ACFT training background →

Test scenes

Shipped as the package's Test Scenes sample; after import they land under Assets/Samples/LiteRT-LM for Unity/<version>/Test Scenes/Scenes/. Regenerate them with the menu LiteRT-LM/Test Scenes/Generate All — scene paths resolve from the import location, so no path editing is needed.

Every scene shows a ◀ Prev / Next ▶ bar so the set can be walked through on a device. Each switch releases the loaded model first — engines hold native memory the GC does not track, so the outgoing one is disposed before the next loads rather than both being resident.

Scene Purpose
LiteRtLmSampleScene Quick start — model path, one prompt, one response
LiteRtLmLlmChatTestScene Multi-turn chat, think/no_think toggle
LiteRtLmAsrTestScene ASR — file / microphone / always-listening (Continuous)
LiteRtLmMultimodalTestScene Image + audio input, with a file picker on Windows
LiteRtLmAsrFunctionCallingTestScene Voice → tool call (15.5 s), editable prompt and tool list
LiteRtLmMultimodalFunctionCallingTestScene Image + utterance → tool call (40.7 s)
LiteRtLmTranslateTestScene Translation — Whisper Direct / ASR+LLM

The Automated Tests sample adds LiteRtLmAndroidSmokeTestScene, LiteRtLmConversationTestScene and LiteRtLmFunctionCallingBenchmarkScene. These start on load and report through an on-screen overlay, so a device run needs no interaction.

Windows runs the same scenes through the bundled CLI binaries, so ASR, translation, multimodal and function calling can all be exercised in the editor before an APK build.

Rebuilding the AAR (after native changes)

Tools/Windows/Build-LiteRtLmUnityAarFromPatch.ps1 -SourceRoot <pristine v0.14.0> applies the patch, builds in Docker and deploys to Packages/com.leuconoe.litert-lm-unity/Runtime/Plugins/Android/.

⚠️ -SkipImageBuild builds the sources baked into the Docker image, so the image must be rebuilt after any patch change.

Docs

Document Contents
docs/llm-details.md LLM tiers, backend choice, device measurements
docs/asr-details.md Every ASR tier, VAD, ACFT-KO training background
docs/README.md Full benchmark and handoff index

The Windows editor path exists only to validate logic before deploying to a device. Its performance profile is the opposite of Android's (GPU wins there), so never use desktop numbers to make device decisions.

About

Unity integration for running LiteRT-LM locally, including Windows Editor tests, Android GPU/OpenCL acceleration, function-calling benchmarks, and a patch-based custom AAR build workflow.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages