Skip to content

fix: migrate StackChan voice assistant to esphome-audio-stack - #120

Merged
parker-int64 merged 12 commits into
m5stack:mainfrom
pfefferle:fix/stackchan-audio-stack
Nov 23, 2026
Merged

parker-int64 merged 12 commits into
m5stack:mainfrom
pfefferle:fix/stackchan-audio-stack

Conversation

@pfefferle

@pfefferle pfefferle commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #93 and the migration discussion in #92.

This moves the StackChan voice assistant from esphome-intercom/i2s_audio_duplex to esphome-audio-stack and reworks the audio pipeline around it.

Review updates

  • Split the previous monolithic commit into focused commits (esp_afe, sendspin, IR proxy, LED effects, sensitivity, wake word location removal).
  • Pinned the audio stack instead of tracking dev.
  • Documented the sdkconfig tuning and the mute/wake-word conditions.

Audio pipeline

  • esphome-intercom@v2026.5.0 → esphome-audio-stack@v2026.12.0-dev (pinned; the dev branch now requires ESPHome 2026.12.0, which is not released yet)
  • esp_aec → esp_afe with the tuned sr/low_cost profile, single-mic AEC and the hardware reference on TDM slot 1. Dual-mic MMR/BSS was too expensive and dropped frames; single-mic AEC measured 0% dropped frames with 28 dB ERLE.
  • ES7210 input and AW88298 output are configured as audio-stack codecs; the standalone audio_adc/audio_dac and the aw_rst switch are gone.
  • Gain staging: 18 dB analog mic gain plus the post-AFE Mic Gain number (6 dB default), 24 dB reference gain, 5 V PA.
  • voice_assistant no longer applies extra NS/AGC/volume; voice_mic is shared by the voice assistant and micro wake word.

Media player

  • Legacy speaker media player → speaker_source + sendspin media player.
  • Music and announcements use separate pipelines; music is ducked during announcements/TTS instead of stopped.
  • play_sound now takes a media URL string.

Other changes

  • IR proxy (ir_rf_proxy) for raw IR TX/RX from Home Assistant (experimental).
  • Voice assistant LED effects on the 12-LED bar.
  • hi_stackchan wake word sensitivity cutoffs measured on LibriSpeech dev-clean.
  • Removed the "Wake word engine location" select; micro wake word always runs on-device on the ESP32-S3.

Validation

  • esphome config passes with ESPHome 2026.10.2 against the pinned audio stack.
  • @parker-int64 verified wake-word detection while music is streaming. A final pass over mute, announcements, LED effects and the IR proxy is still open.

/cc @n-IA-hane

@parker-int64

parker-int64 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the PR, I have a AW88298 PR on the way.

Maybe we can wait until the PR gets reviewed (merged), then switch to hardware AEC on TDM. That should give us better audio results while reducing CPU usage.

@parker-int64

Copy link
Copy Markdown
Contributor

n-IA-hane/esphome-audio-stack#16 is merged into dev. And I have added some additional TDM configurations (still testing on cores3 for better performance).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The obsolete standalone amplifier driver fails by probing the device while it is held in reset, and unresolved dependency-pinning and custom-image regressions remain.

3 open issues
What changed in this PR

Migrates the shared StackChan voice-assistant package from esphome-intercom to esphome-audio-stack, following the compatibility repair in #93.

Changes:

  • Replaces duplex audio components with Audio Stack and configures codec management and hardware echo-reference routing.
  • Raises the minimum ESPHome version, adjusts ESP-IDF settings, and updates the playback script for const audio files.
  • Updates external component sources and migrates image entries to platform: file with explicit URLs.
File Description
common/​stackchan-voice-assistant-base.yaml Updates StackChan audio integration, runtime settings, playback types, and image configuration.

Review effort: Balanced

@parker-int64

Copy link
Copy Markdown
Contributor

I had some more adjustments and modifications, they aren't just about the esphome-audio-stack; they also cover other aspects. I'm very sorry I didn't keep each PR focused on its own content (there were quite a few local modifications).

Mainly migrate to the esp_afe instead of esp_aec for better AEC result, however only one mic was used for AEC, since dual mic configuration lags on my side and constantly trigger WDT.

I have tested on at my end and I can wake the device while streaming the music.

@pfefferle

Copy link
Copy Markdown
Contributor Author

Whatever helps improving it 😊

@pboushy pboushy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few feedback items from me.

In addition, the last commit is a ton of changes in one commit and will make troubleshooting and reverting if needed a mess. Can you split it up?

I would propose breaking it up into the below (not in order, numbering is for reference):

  1. feat: Migrate esp_aec to esp_afe
  2. feat: Migrate media player to sendspin
  3. feat: Add new IR proxy
  4. feat: Add light effect to voice assistant trigger
  5. feat: Adjust hi_stackchan wakeword sensitivity
  6. Remove Wake Word engine location

Please include the reason for 1, 2, and 6 in the commit messages.

@parker-int64

Copy link
Copy Markdown
Contributor

Too many changes combined with vague commit messages make a PR hard to review and move forward. I'll continue addressing the review feedback.

parker-int64 and others added 10 commits November 19, 2026 16:15
- Move the custom components from this repo to m5stack/esphome@m5-dev so
  they can be prepared for upstream ESPHome PRs.
- Move esphome-audio-stack from v2026.11.0 to dev: the AW88298 codec and
  the TDM reference options are not in the release yet. The audio stack
  now owns the ES7210 input, the AW88298 output and the AW_RST pin, so
  drop the standalone reset switch.
- Configure the four TDM slots: MIC1 on slot 0, the hardware AEC
  reference on slot 1, playback on slot 0, and keep the buffers and the
  audio task stack in PSRAM.
- Use platform: file for the images to fix the ESPHome 2026.10
  deprecation warning.
- Document the sdkconfig tuning: the cache and PSRAM options reduce
  PSRAM latency and move code, read-only data, Bluetooth and mbedTLS
  buffers to PSRAM, which speeds up micro wake word.
Replace the single-mic esp_aec processor with the full ESP-SR front end.
The AFE uses the tuned sr/low_cost profile with AEC on; NS and AGC stay
off because the codec gain staging handles the level.

Use a single microphone: Espressif's ESP32-S3 benchmark puts the dual-mic
MMR/BSS profile at 23.7% feed + 22.9% fetch of one core versus 8.8% +
9.8% for the single-mic profile, and the dual-mic feed path dropped 14.6%
of its frames while music was playing. Single-mic AEC measured 0% dropped
frames with 28 dB of echo return loss.

The codec now owns the ES7210 input and the AW88298 output, so remove the
standalone audio_adc/esp_aec components and the unused m5ioe1 test
output. Lower the analog mic gain to 18 dB for headroom and compensate
with the new post-AFE Mic Gain number; raise the reference gain to 24 dB
and use the 5 V PA voltage expected by the CoreS3 BSP.

Rename the microphone entity to voice_mic because the voice assistant and
micro wake word consume the same AFE-processed stream, and add
start_wake_word so the engine is restarted consistently after voice
assistant sessions and unmute. Raise the BSP I2C bus to 100 kHz for the
codec/PMU traffic.

The loopTask priority change is a workaround for the AFE feed deadline;
keep it isolated here so it can be revisited separately.
Replace the legacy speaker media player with speaker_source and the
sendspin media player. The new pipelines separate music (two channels,
HTTP and sendspin sources) from announcements (audio_file and HTTP
sources), which lets the stack duck music while TTS or the wake sound
plays instead of stopping playback.

Add the sendspin hub/source and the audio_file media source, restore
ducking when an announcement ends and when the voice assistant finishes,
and let the player restart micro wake word when user playback ends.
play_sound now takes a media URL string because the speaker_source API
plays audio through the media source pipeline.
Expose the existing IR TX/RX pins as ir_rf_proxy entities so the device
can learn and replay arbitrary IR codes from Home Assistant. This is an
experimental convenience on top of the Coolix climate support; the
receiver no longer dumps every protocol to the log.
Add a partition light over the 12-LED bar and drive it from the voice
assistant phase: initializing, listening, thinking, replying, error,
muted and not-ready patterns. The pattern follows the user's chosen bar
colour when the bar is on and falls back to assistant cyan. The effect is
selected from draw_display so it stays in sync with the display and with
connection changes.
Add cutoffs for the hi_stackchan model, measured on LibriSpeech dev-clean
because it has no DipCo figures. The model is more trigger happy than the
others, so use smaller steps and keep the manifest default at the middle
tier.
Always run micro wake word on the ESP32-S3. Streaming all microphone
audio to Home Assistant just for wake word detection adds latency and
network overhead, and the on-device model is fast enough. This also drops
the start_continuous path and the on_end workaround that existed only for
the "In Home Assistant" mode. The same cleanup will be rolled out to the
other ESP32-S3 voice assistant devices.
The dev branch moved to ESPHome 2026.12.0, so the current config no longer
validates with the declared minimum 2026.10.0. v2026.12.0-dev is the tested
snapshot with AW88298, esp_afe and the TDM reference support, and it
validates with ESPHome 2026.10.2. Pin it so builds do not change between
reviews; move to a stable tag once one contains these features.
@parker-int64
parker-int64 force-pushed the fix/stackchan-audio-stack branch from b5bbba4 to bcf3c95 Compare November 19, 2026 08:25
@parker-int64

parker-int64 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

History rewritten in bcf3c95:

 $ esphome config common/stackchan-voice-assistant-base.yaml
INFO ESPHome 2026.10.0
INFO Reading configuration common/stackchan-voice-assistant-base.yaml...
...
INFO Configuration is valid!
$ esphome compile common/stackchan-voice-assistant-base.yaml
INFO ESPHome 2026.10.0
INFO Reading configuration common/stackchan-voice-assistant-base.yaml...
stackchan-voice.bin binary size 0x52a410 bytes. Smallest app partition is 0x7c0000 bytes. 0x295bf0 bytes (33%) free.
RAM:   [=====     ]  48.3% (used 165212 bytes from 341760 bytes)
Flash: [=======   ]  66.6% (used 5415828 bytes from 8126464 bytes)
INFO Creating factory.bin...
...
INFO Successfully compiled program.

Config and compile/test looks good to me.

  • Split the previous monolithic commit into focused commits: esp_afe, sendspin, IR proxy, LED effects, hi_stackchan sensitivity, and removal of the wake word location select.
  • Added the missing sdkconfig/mute/wake-word comments.
  • Pinned esphome-audio-stack to v2026.12.0-dev. The dev branch now requires ESPHome 2026.12.0, so the previous ref no longer validated with 2026.10.0.
  • Updated the PR description with the full scope and validation status.

esphome config passes with ESPHome 2026.10.0. @pboushy could you take another look?

@parker-int64
parker-int64 merged commit bc507b5 into m5stack:main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants