#!/bin/bash
set -e
sleep 5
# First, set the master source volume to 200%
pactl set-source-volume "alsa_input.usb-R__DE_R__DE_VideoMic_GO_II_FEB0C614-00.mono-fallback" 131072
pactl set-source-mute "alsa_input.usb-R__DE_R__DE_VideoMic_GO_II_FEB0C614-00.mono-fallback" 0
# Unload then load AEC module
pactl unload-module module-echo-cancel || true
pactl load-module module-echo-cancel \
use_master_format=1 \
aec_method=webrtc \
source_master="alsa_input.usb-R__DE_R__DE_VideoMic_GO_II_FEB0C614-00.mono-fallback" \
sink_master="alsa_output.platform-88090b0000.had.hdmi-stereo" \
source_name="default_mic_aec" \
sink_name="default_output_aec" \
source_properties="device.description=Microphone_with_AEC" \
sink_properties="device.description=Speaker_with_AEC"
# Wait a moment for the module to fully initialize
sleep 2
# Set defaults
pactl set-default-source default_mic_aec
pactl set-default-sink default_output_aec
# Retry volume setting until device appears and volume is set correctly
for i in {1..15}; do
if pactl list short sources | grep -q default_mic_aec; then
# Set volume to 200% (131072)
pactl set-source-volume default_mic_aec 131072
pactl set-source-mute default_mic_aec 0
# Verify the volume was set
CURRENT_VOL=$(pactl list sources | grep -A 7 "Name: default_mic_aec" | grep "Volume:" | awk '{print $3}')
if [ "$CURRENT_VOL" = "131072" ]; then
echo "Microphone volume successfully set to 200%"
break
else
echo "Volume is $CURRENT_VOL, retrying... ($i/15)"
fi
else
echo "Waiting for AEC source to appear... ($i/15)"
fi
sleep 1
done
# Final verification
pactl list sources | grep -A 7 "Name: default_mic_aec" | grep -E "Name:|Volume:"