Skip to main content
This tutorial shows how to run a keyword spotting model on Android for wake word detection, voice commands, and audio event recognition.

What you’ll build

Keyword Spotting on Android An Android app that:
  • Captures real-time audio from microphone
  • Recognizes spoken keywords continuously
  • Displays classification results with confidence scores
  • Runs entirely on-device with low latency

Prerequisites

  • Trained audio keyword spotting model
  • Android Studio with NDK and CMake
  • Android device with microphone (usb camera with a mic also works)
  • Basic familiarity with Android development

1. Clone the repository

2. Download TensorFlow Lite libraries

3. Export your audio model

  1. In Edge Impulse Studio, go to Deployment
  2. Select Android (C++ library)
  3. Enable EON Compiler (recommended for audio)
  4. Click Build and download the .zip

4. Integrate the model

  1. Extract the downloaded .zip file
  2. Copy all files except CMakeLists.txt to:
Your structure should be:

5. Configure audio permissions

Permissions are already set in AndroidManifest.xml:

6. Build and run

  1. Open in Android Studio
  2. Build → Make Project
  3. Connect your Android device
  4. Run the app
  5. Grant microphone permission when prompted
Run the app and speak your keywords.

How it works

Audio capture

Ring buffer for continuous inference

Native inference

Result display

Troubleshooting

Confirm <uses-permission android:name="android.permission.RECORD_AUDIO" /> is in AndroidManifest.xml and that you call ActivityCompat.requestPermissions on first launch. Grant the permission manually under Settings → Apps → … → Permissions if the system dialog never appears.
  • Verify the sample rate in MainActivity.kt matches the value reported by ei_classifier_frequency() (16 kHz for most KWS models).
  • Confirm EI_CLASSIFIER_SLICE_SIZE matches the slice size you read from the microphone before each run_classifier_continuous call.
  • Make sure your model was exported with EON Compiler enabled and that the labels in ei_classifier_inferencing_categories match what you trained on.
The bundled full TensorFlow Lite runtime uses aligned_alloc, which is only available from Android API 28 onwards. Bump minSdk to at least 28 in app/build.gradle.kts.
The native library failed to load. Confirm ndk { abiFilters += "arm64-v8a" } is set in app/build.gradle.kts and that download_tflite_libs.sh placed .a files in app/src/main/cpp/tflite/android64/.

Next steps

Resources