Skip to main content
Deploy audio keyword spotting models on Zephyr using the Edge Impulse Zephyr Module. Drop in your model → build → flash → get real-time audio inference.
This tutorial adapts the IMU inference example for audio keyword spotting. The key differences are replacing the IMU sensor driver with Zephyr’s DMIC (Digital Microphone) API and adjusting the inference pipeline for continuous audio classification.
Reference code: https://github.com/edgeimpulse/ei-zephyr-mic-kws-inference

What You’ll Build

A Zephyr application that:
  • Captures real-time audio from PDM microphone
  • Runs continuous keyword spotting inference
  • Displays classification results via serial
  • Works on any Zephyr board with PDM microphone support

Prerequisites

Supported Microphones

PDM microphones accessible through Zephyr’s DMIC (Digital Microphone) driver are compatible:

1. Initialize the Repository

This fetches:
  • Zephyr RTOS
  • Edge Impulse Zephyr SDK module
  • All dependencies

2. Deploy Your Audio Model

In Edge Impulse Studio:
  1. Go to Deployment
  2. Select Zephyr library
  3. Click Build
  4. Download the model .zip
Extract into model/:
Ensure model/ contains:
  • CMakeLists.txt
  • edge-impulse-sdk/
  • model-parameters/
  • tflite-model/

3. Build

Select your board:
Or configure in .west/config:
Then build:

4. Flash

Alternative flash runners:

5. Monitor Output

Expected output:

How It Works

Adapting from IMU to Audio

This example follows the same architecture as the IMU inference tutorial, with these key changes: The inference loop, circular buffer, and Edge Impulse integration remain the same—only the sensor interface changes.

Code Flow

  1. Initialize - Set up microphone via Zephyr DMIC API
  2. Sample - Continuous audio data collection at model frequency
  3. Buffer - Circular buffer stores audio samples
  4. Infer - Run classifier when buffer is full
  5. Output - Print classification results
  6. Loop - Repeat

Project Structure

Customizing the Example

Adjust Audio Sampling

In prj.conf:

Change Inference Frequency

In src/main.cpp:

Increase Memory for Larger Models

In prj.conf:

Add Logging

Understanding the Code

Microphone Initialization

Audio Capture

Inference Integration

Main Loop

Device Tree Configuration

For boards without built-in DMIC, add to your .overlay file:

Troubleshooting

Cause: Edge Impulse SDK not fetchedSolution:
Cause: Model too large for available RAMSolution: Increase stack size in prj.conf:
Or enable EON Compiler when deploying from Studio.
Cause: DMIC device not configured or pins incorrectSolution: Enable debug logging:
Check device tree configuration matches your board’s microphone pins.
Causes & Solutions:
  1. Wrong sample rate: Verify CONFIG_AUDIO_SAMPLE_RATE_16000=y matches your model
  2. Buffer underrun: Increase buffer size:
  1. Clock configuration: Check PDM clock frequency in device tree
Causes & Solutions:
  1. Background noise: Train model with noise samples
  2. Microphone gain: Adjust in device tree:
  1. Sample rate mismatch: Ensure DMIC sample rate matches training data

Using in Your Own Project

Option 1: Add to Existing Zephyr Project

Update your west.yml:
Then:
Add to your CMakeLists.txt:

Option 2: Clone This Repository

Advanced Features

Voice Activity Detection (VAD)

Only run inference when speech is detected:

Continuous Sliding Window

Wake Word Detection

Performance Optimization

Reduce Power Consumption

Use DMA for Audio Transfer

Optimize for Size

Next Steps

IMU Inference

Add motion recognition

Porting Between Boards

Deploy to different hardware

Additional Resources

Summary

You now have microphone-based keyword spotting running on Zephyr! The Edge Impulse Zephyr Module handles:
  • Audio capture from PDM microphones
  • Continuous inference pipeline
  • Model integration
  • Memory management
Focus on building your application logic while the module handles the ML complexity. For more information: