diff --git a/.env.example b/.env.example index e5480046..121f1262 100644 --- a/.env.example +++ b/.env.example @@ -45,11 +45,19 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" ### Audio output device (optional): # AUDIO_OUTPUT_DEVICE="default" +<<<<<<< feat/docker-aec-env-var +### 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" +======= ### Mic Gain (optional) passed as an argument to LVA will overide the value in thepreferences file on boot but can be changed at runtime in Home Assistant: # MIC_AUTO_GAIN="0" ### Mic Noise Suppression (optional) passed as an argument to LVA will overide the value in thepreferences file on boot but can be changed at runtime in Home Assistant: # MIC_NOISE_SUPPRESSION="0" +>>>>>>> main ### Enable thinking sound (optional): # ENABLE_THINKING_SOUND="1" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2eae2297..ced43990 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -135,6 +135,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