Skip to main content
This tutorial runs a keyword spotting model on Android. You can use the same approach for wake words, voice commands, and other audio events.
Android keyword spotting app showing the detected keyword and its confidence score

What you’ll build

An Android app that:
  • Captures audio from the microphone
  • Classifies the audio continuously on-device
  • Displays the detected keyword and its confidence score

Prerequisites

  • A trained keyword spotting model
  • Android Studio with the NDK and CMake installed
  • An Android device with a microphone (a USB camera with a built-in microphone also works)

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.
  4. Click Build and download the .zip file.

4. Integrate the model

Extract the downloaded .zip file and copy its contents, except CMakeLists.txt, into example_kws/app/src/main/cpp/. The folder then looks like this:

5. Check the audio permissions

AndroidManifest.xml already declares the microphone permission:

6. Build and run

  1. Open the project in Android Studio.
  2. Select Build -> Make Project.
  3. Connect your Android device.
  4. Run the app and grant the microphone permission when prompted.
Speak one of your keywords. The app shows the detected keyword and its confidence score.

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. If the system dialog never appears, grant the permission under Settings -> Apps -> your app -> Permissions.
  • 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 TensorFlow Lite runtime uses aligned_alloc, which needs Android API 28 or later. Set minSdk to 28 or higher 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