audio_afe

Example of the component jason-mao/av_processor v0.6.0
# 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 prompt 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.

## 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
- **prompt 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/lai_lo.mp3` through the prompt 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, prompt 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 `lai_lo.mp3` 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/lai_lo.mp3`

To create a project from this example, run:

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

or download archive (~3.75 MB)