From 124e312c869e0b4490afd891572d91c8b56fe140 Mon Sep 17 00:00:00 2001 From: Vlad Gevsky Date: Tue, 24 Mar 2026 03:33:15 +0100 Subject: [PATCH] Add ENABLE_ECHO_CANCEL env var for Docker AEC setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docker users currently have to manually SSH into the host, run pactl commands, and set AUDIO_INPUT_DEVICE by hand — steps that don't persist across PulseAudio restarts. This adds a single env var that automates exactly the setup already described in docs/enabling_aec.md. When ENABLE_ECHO_CANCEL=1 is set, the entrypoint loads module-echo-cancel with source_name=aec_mic and sets AUDIO_INPUT_DEVICE to aec_mic automatically. If the module fails to load a warning is logged and the application starts normally with the default devices. Updates docs/enabling_aec.md with a Docker section and .env.example with documentation for the new variable. --- .env.example | 6 ++++++ docker-entrypoint.sh | 18 ++++++++++++++++++ docs/enabling_aec.md | 12 +++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 9e062239..c3465f8a 100644 --- a/.env.example +++ b/.env.example @@ -41,6 +41,12 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" ### Audio output device (optional): # AUDIO_OUTPUT_DEVICE="default" +### Acoustic Echo Cancellation (optional): +# Automatically loads the PulseAudio AEC module and sets AUDIO_INPUT_DEVICE +# to the echo-cancelled source. See docs/enabling_aec.md for details and +# for PipeWire / manual setup instructions. +# ENABLE_ECHO_CANCEL="1" + ### Enable thinking sound (optional): # ENABLE_THINKING_SOUND="1" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4d7b023e..1c163f7d 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -120,6 +120,24 @@ for i in $(seq 1 $CP_MAX_RETRIES); do done +### Acoustic Echo Cancellation +# Convenience wrapper for the setup described in docs/enabling_aec.md. +# Loads the PulseAudio AEC module and sets AUDIO_INPUT_DEVICE automatically. +# See docs/enabling_aec.md for manual setup and PipeWire instructions. +if [ "${ENABLE_ECHO_CANCEL}" = "1" ]; then + if pactl list modules short 2>/dev/null | grep -q module-echo-cancel; then + echo "✅ Echo cancellation module already loaded" + else + if pactl load-module module-echo-cancel source_name=aec_mic aec_method=webrtc; then + echo "✅ Echo cancellation enabled" + else + echo "⚠️ Failed to load echo cancellation module (continuing without it)" + fi + fi + AUDIO_INPUT_DEVICE="${AUDIO_INPUT_DEVICE:-aec_mic}" +fi + + ### Start application if [ "$LIST_DEVICES" = "1" ]; then echo "list input devices" diff --git a/docs/enabling_aec.md b/docs/enabling_aec.md index cc8283f1..c7171d21 100644 --- a/docs/enabling_aec.md +++ b/docs/enabling_aec.md @@ -2,7 +2,17 @@ Acoustic Echo Cancellation (AEC) is a type of sound processing used to cancel out the noise coming out of your speaker and going into your mic. In LVA this functionality can be useful to allow LVA to listen to wake words even when audio is playing, particularly when a timer is playing. PulseAudio and PipeWire already provide built-in modules for AEC. -## Enabling AEC +## Docker + +Set `ENABLE_ECHO_CANCEL=1` in your `.env` file. The container will automatically load the PulseAudio AEC module and set `AUDIO_INPUT_DEVICE` to `aec_mic` at startup. If the module fails to load, a warning is logged and the application continues with the default audio devices. + +```env +ENABLE_ECHO_CANCEL=1 +``` + +For PipeWire or custom configurations, use the manual setup below and set `AUDIO_INPUT_DEVICE` directly. + +## Manual Setup ### PulseAudio ```sh