Android Studio sample collection for running ailia SDK models from Kotlin. Each Ailia*Sample.kt keeps model download, preprocessing, inference, postprocessing, and resource release close together so one model can be copied into another application without bringing MainActivity with it.
- macOS / Windows 11
- Android Studio 2025.1.3
- Gradle 8.13.2
- Kotlin 1.8.22
- minSdk 21 / targetSdk 35
- ailia SDK 1.5.0
Fetch the JNI modules, then open the repository root in Android Studio.
git submodule update --init --recursiveModels bundled in res/raw run without a download. Other models are downloaded when Run, Record, Generate, or Send is pressed and are stored in the application's durable model directory. A progress bar is shown while a transfer is active.
| Category | Model sample | Runtime |
|---|---|---|
| Pose Estimation | Lightweight Human Pose Estimation | ailia SDK |
| Object Detection | YOLOX TFLite, YOLOX ONNX, DETR ResNet50 | ailia TFLite Runtime / ailia SDK |
| Object Tracking | ByteTrack with YOLOX | ailia Tracker + detector runtime |
| Image Classification | MobileNetV2 / ResNet50 TFLite, MobileNetV2 / ResNet50 / ViT-B/16 ONNX | ailia TFLite Runtime / ailia SDK |
| Background Removal | U-2-Net | ailia SDK |
| Zero-Shot Classification | multilingual-MiniLMv2 L12 | ailia Tokenizer + ailia SDK |
| Speech to Text | Whisper / SenseVoice Small | ailia AI Speech |
| Speaker Verification | WeSpeaker ResNet34 (VoxCeleb) + Silero VAD v6 | ailia SDK |
| Voice Filtering | VoiceFilter + dynamic d-vector embedder + Silero VAD v6 | ailia SDK |
| Text to Speech | GPT-SoVITS V1 / V2 / V3 / V2-Pro / V2-Pro Distill JA | ailia AI Voice |
| LLM | Gemma 4 E2B / E4B / Gemma 2 2B | ailia LLM |
| Multimodal LLM | Gemma 3 4B | ailia LLM |
Add only the JNI modules needed by the selected sample.
| Sample | Required Gradle modules |
|---|---|
| ONNX vision, U-2-Net, DETR | ailia-sdk-jni |
| TFLite vision | ailia-tflite-jni |
| ByteTrack | ailia-tracker-jni plus the selected detector runtime |
| multilingual-MiniLMv2 | ailia-sdk-jni, ailia-tokenizer-jni |
| Whisper / SenseVoice | ailia-speech-jni |
| WeSpeaker + Silero VAD v6 | ailia-sdk-jni |
| VoiceFilter + Silero VAD v6 | ailia-sdk-jni |
| GPT-SoVITS | ailia-voice-jni, ailia-audio-jni, ailia-sdk-jni |
| Gemma text or multimodal | ailia-llm-jni |
For a downloadable model, also copy ModelDownloader.kt. It uses a temporary file, validates HTTP status and size, records a SHA-256 sidecar, and only then moves the model into place. The sample constructors require a model directory so storage ownership is explicit.
val modelDirectory = ModelDownloader.modelDirectory(context)
val sample = AiliaDetrSample(modelDirectory)
executor.execute {
if (sample.downloadModel() && sample.initialize(environmentId)) {
val inference = sample.detect(bitmap)
val detections: List<DetectionResult> = inference?.value.orEmpty()
}
}Run native initialization, inference, and release on the same serial executor. Do not release a model from the UI thread while inference is active.
The inference-facing result classes are independent of the SDK wrappers:
- Detection and tracking:
DetectionResult.kt,ModelInferenceResult.kt,CocoLabels.kt, andCategoryColors.kt - Classification:
ClassificationResult.kt,ModelInferenceResult.kt, andImageNetLabels.kt - Background removal:
ModelInferenceResult.kt(SegmentationMask) - Speaker verification:
SpeakerVerificationAudio.ktand the session-onlySpeakerProfileStore.kt - Voice filtering:
VoiceFilterAudio.ktand the session-onlySpeakerProfileStore.kt
detect, classify, and predictMask return typed results without drawing. drawDetections and drawMask are optional Android renderers. The process... methods remain small compatibility wrappers used by the demo UI.
Models in res/raw must be copied with their sample. Downloaded filenames and URLs are declared beside each model enum or at the top of its sample class. INTERNET is required for those downloads; CAMERA and RECORD_AUDIO are requested only when the corresponding feature is used.
| Pose Estimation | Object Detection | Tracking |
![]() |
![]() |
|
| Classification | Zero-Shot Classification | Speech to Text |
![]() |
![]() |
![]() |
| Text to Speech | LLM | Multimodal LLM |
![]() |
![]() |
![]() |







