Files
linux-voice-assistant/docker-entrypoint.sh
T
aryanhasgithub 4ee7bb04bc Add support for WebRTC Auto Gain and Noise Suppression (#250)
## WebRTC Auto Gain & Noise Suppression
 
This PR adds support for WebRTC Auto Gain and Noise Suppression as previously implemented in the Wyoming Satellite project.
 
### What's New
 
Two new entities have been created a number slider for gain and another one for noise suppression. The processing happens inside of the `webrtc.py` file and is implemented in the `__main__.py` file's `process_audio` function. The slider for gain has a limit of 0-31 and noise suppression has a limit of 0-4.
 
The Auto Gain and Noise Suppression persist through restarts and are saved as preferences. The values are dynamically chnged without needing a restart.
 
CLI flags called `--mic-auto-gain` and `--mic-noise-suppression` have also been added.
 
>  When both values are 0, WebRTC processing is bypassed entirely with no performance overhead.

Closes #25 
 
### Testing
 
When saving the audio recorded by LVA there is a noticeable increase. The following two files have been recorded with similar audio being played through them with these results (Gain-31 and NS-4):
 
| Metric | With AGC+NS | Without |
|---|---|---|
| Max amplitude | 0.329 | 0.054 |
| RMS amplitude | 0.008905 | 0.002862 |
| Volume adjustment needed | 3.034x | 13.479x |
| Rough frequency | 916 Hz | 705 Hz |
2026-04-09 00:43:11 +02:00

146 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
set -e
### Handlers
# Handle parameters
EXTRA_ARGS=()
if [ "$ENABLE_DEBUG" = "1" ]; then
EXTRA_ARGS+=( "--debug" )
fi
if [ -n "${CLIENT_NAME}" ]; then
EXTRA_ARGS+=( "--name" "$CLIENT_NAME" )
fi
PREFERENCES_FILE=${PREFERENCES_FILE:-"/app/configuration/preferences.json"}
if [ -n "${PREFERENCES_FILE}" ]; then
EXTRA_ARGS+=( "--preferences-file" "$PREFERENCES_FILE" )
fi
if [ -n "${NETWORK_INTERFACE}" ]; then
EXTRA_ARGS+=( "--network-interface" "$NETWORK_INTERFACE" )
fi
# IP-ADDRESS
if [ -n "${HOST}" ]; then
EXTRA_ARGS+=( "--host" "$HOST" )
fi
PORT=${PORT:-6053}
if [ -n "${PORT}" ]; then
EXTRA_ARGS+=( "--port" "$PORT" )
fi
if [ -n "${AUDIO_INPUT_DEVICE}" ]; then
EXTRA_ARGS+=( "--audio-input-device" "$AUDIO_INPUT_DEVICE" )
fi
if [ -n "${AUDIO_OUTPUT_DEVICE}" ]; then
EXTRA_ARGS+=( "--audio-output-device" "$AUDIO_OUTPUT_DEVICE" )
fi
if [ -n "${MIC_AUTO_GAIN}" ]; then
EXTRA_ARGS+=( "--mic-auto-gain" "$MIC_AUTO_GAIN" )
fi
if [ -n "${MIC_NOISE_SUPPRESSION}" ]; then
EXTRA_ARGS+=( "--mic-noise-suppression" "$MIC_NOISE_SUPPRESSION" )
fi
if [ "$ENABLE_THINKING_SOUND" = "1" ]; then
EXTRA_ARGS+=( "--enable-thinking-sound" )
fi
if [ -n "${WAKE_WORD_DIR}" ]; then
EXTRA_ARGS+=( "--wake-word-dir" "$WAKE_WORD_DIR" )
fi
if [ -n "${WAKE_MODEL}" ]; then
EXTRA_ARGS+=( "--wake-model" "$WAKE_MODEL" )
fi
if [ -n "${STOP_MODEL}" ]; then
EXTRA_ARGS+=( "--stop-model" "$STOP_MODEL" )
fi
if [ -n "${REFACTORY_SECONDS}" ]; then
EXTRA_ARGS+=( "--refractory-seconds" "$REFACTORY_SECONDS" )
fi
if [ -n "${WAKEUP_SOUND}" ]; then
EXTRA_ARGS+=( "--wakeup-sound" "$WAKEUP_SOUND" )
fi
if [ -n "${TIMER_FINISHED_SOUND}" ]; then
EXTRA_ARGS+=( "--timer-finished-sound" "$TIMER_FINISHED_SOUND" )
fi
if [ -n "${PROCESSING_SOUND}" ]; then
EXTRA_ARGS+=( "--processing-sound" "$PROCESSING_SOUND" )
fi
if [ -n "${MUTE_SOUND}" ]; then
EXTRA_ARGS+=( "--mute-sound" "$MUTE_SOUND" )
fi
if [ -n "${UNMUTE_SOUND}" ]; then
EXTRA_ARGS+=( "--unmute-sound" "$UNMUTE_SOUND" )
fi
if [ -n "${TIMER_MAX_RING_SECONDS}" ]; then
EXTRA_ARGS+=( "--timer-max-ring-seconds" "$TIMER_MAX_RING_SECONDS" )
fi
if [ "$ENABLE_OUTPUT_ONLY" = "1" ]; then
EXTRA_ARGS+=( "--output-only" )
fi
# Add cookie file for pulseaudio to prevent errors
PULSE_COOKIE=${PULSE_COOKIE:-"/run/user/1000/pulse/cookie"}
if [[ "$PULSE_COOKIE" != "DISABLED" ]]; then
if [ ! -f "$PULSE_COOKIE" ]; then
echo "Creating PulseAudio cookie file at $PULSE_COOKIE"
touch "$PULSE_COOKIE"
chmod 600 "$PULSE_COOKIE"
fi
fi
### Wait for PulseAudio
# Wait for PulseAudio to be available before starting the application
CP_MAX_RETRIES=30
CP_RETRY_DELAY=1
### while maybe besser?
echo "Checking PulseAudio service status..."
for i in $(seq 1 $CP_MAX_RETRIES); do
# Check if PulseAudio is running
if pactl info >/dev/null 2>&1; then
echo "✅ PulseAudio is running"
break
fi
if [ $i -eq $CP_MAX_RETRIES ]; then
echo "❌ PulseAudio did not start after $CP_MAX_RETRIES seconds"
exit 2
fi
echo "⏳ PulseAudio not running yet, retrying in $CP_RETRY_DELAY s..."
sleep $CP_RETRY_DELAY
done
### Start application
if [ "$LIST_DEVICES" = "1" ]; then
echo "list input devices"
./script/run "$@" "${EXTRA_ARGS[@]}" --list-input-devices
echo "list output devices"
./script/run "$@" "${EXTRA_ARGS[@]}" --list-output-devices
echo "wait 20s and then starting the application"
sleep 20
fi
echo "starting application"
exec ./script/run "$@" "${EXTRA_ARGS[@]}"