audio_afe

Example of the component jason-mao/av_processor v0.7.1
# Audio AFE Example

## Introduction

This example demonstrates how to use the `av_processor` component in built-in AFE frontend mode. It provides a microphone-to-speaker loopback flow with wakeup prompt playback: `audio_recorder` captures audio after AFE processing, `audio_feeder` plays the processed stream back in real time, and a dedicated high-priority player plays a tone from SPIFFS after wake word detection.

## Hardware Requirements

This example is implemented based on the **ESP32-S3-KORVO2-V3** development board, which integrates a microphone array and speakers and is suitable for testing AFE processing such as AEC, NS, VAD, and AGC.

Board setup:

```bash
. ./prebuild.sh                 # select target: esp32s3
idf.py gen-bmgr-config -b esp32_s3_korvo2_v3
idf.py build flash monitor
```

## Custom Wake Word (小谷同学)

This example uses a **local** `esp-sr` **2.5.3** (override) with a custom WakeNet10 model:

- Local component: [`esp-sr`](./esp-sr) via `override_path` in `main/idf_component.yml`
- Model folder: `esp-sr/model/wakenet_model/wn10_xiao3gu3tong2xue2`
- Kconfig: `CONFIG_SR_WN_WN10_XIAO3GU3TONG2XUE2` (enabled in `sdkconfig.defaults`)

> Note: This model is **WakeNet10** (`wn10_*` / log prefix related to wakenet10), not WakeNet9l. The older `wn9l_*` customization guide does not apply to this package.

After wakeup, you should see WakeNet10 init logs for `xiao3gu3tong2xue2` / 小谷同学.

## Feature Description

### av_processor Component

The `av_processor` component provides a unified audio processing interface, mainly including the following functional modules:

- **audio_recorder (Recorder)**: Captures audio data from the microphone and runs the built-in `ai_afe` frontend
- **audio_feeder (Player)**: Feeds processed audio into the playback pipeline for real-time playback
- **high-priority player**: Plays the wakeup prompt tone when the wakeup start event is reported
- **AFE frontend**: Enables integrated wakeup, AEC, NS, VAD, and AGC in the esp-sr based frontend path

### AFE Loopback Flow

This example focuses on the built-in AFE wakeup path:

1. **Recording**: Capture microphone audio through `audio_recorder`
2. **AFE processing**: Run the built-in `ai_afe` frontend with wakeup, AEC, NS, VAD, and AGC enabled
3. **Wakeup prompt**: Play `/spiffs/I_comeon_wakeup.wav` through the high-priority player after `WAKEUP_START`
4. **Playback**: Feed the processed PCM stream into `audio_feeder` for near real-time monitoring

Implementation flow:

- Initialize the board audio path and register callback-based record/playback I/O
- Mount the `spiffs_data` partition and expose prompt files under `/spiffs`
- Configure the recorder to use `DEFAULT_AV_PROCESSOR_AFE_CONFIG()`
- Enable AEC, NS, VAD, and AGC in AFE wakeup mode
- Open the recorder, playback, high-priority player, and feeder modules
- Trigger prompt playback in the `ESP_GMF_AFE_EVT_WAKEUP_START` event callback
- Continuously read processed audio from the recorder and push it into the feeder

## Usage Instructions

1. Execute the `. ./prebuild.sh` script and select the development board model according to the prompts
2. Use the `idf.py flash monitor -p` command to flash and run the program
3. During build, the `I_comeon_wakeup.wav` file in [spiffs](/home/xutao/workspace-20/av_processor_v2/examples/audio_afe/spiffs) is packed into the `spiffs_data` partition
4. After running, say the wake word and the board will first play the prompt tone
5. Then speak into the microphone and listen to the AFE-processed loopback audio from the speaker

## Configuration Parameters

- Sample rate: 16000 Hz
- Bit depth: 16 bit recorder output / playback data
- Channels: 1
- Frame duration: 20 ms
- Prompt file: `file://spiffs/I_comeon_wakeup.wav`

To create a project from this example, run:

idf.py create-project-from-example "jason-mao/av_processor=0.7.1:audio_afe"

or download archive (~94.86 KB)