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 |
This commit is contained in:
1 parent
341e3dcb9c
commit
4ee7bb04bc
11 files changed
+330
-11
No files matched your search
@@ -0,0 +1,49 @@
|
||||
# Audio Options: Gain and Noise Suppression
|
||||
|
||||
## What do Gain and Noise Suppression do
|
||||
|
||||
### Gain
|
||||
|
||||
When you change gain, LVA(using the webrtc library) automatically adjusts the microphone input volume to keep it at a consistent level. If you're speaking quietly it boosts the signal, if you're speaking loudly it reduces it. Useful in the following ways:-
|
||||
|
||||
- Microphones that are too quiet by default
|
||||
- Environments where you move around relative to the mic
|
||||
- Keeping wake word detection consistent regardless of speaking volume
|
||||
|
||||
### Noise Suppression
|
||||
|
||||
When you change noise suppression, LVA(using the webrtc library) filters out constant background noise from the audio signal. It works by learning what "silence" sounds like in your environment and subtracting that from the audio. Useful in the following ways:
|
||||
|
||||
- Noisy environments
|
||||
- Improving STT accuracy by sending cleaner audio to Home Assistant
|
||||
- Reducing false wake word triggers from background noise
|
||||
|
||||
## Using Gain and Noise Suppression with LVA
|
||||
|
||||
LVA implements gain and Noise Suppression in two ways:
|
||||
|
||||
- [CLI Argument/ENV file](#cli-argumentenv-file)
|
||||
- [Home Assistant Entity](#home-assistant-entity)
|
||||
|
||||
### CLI Argument/ENV file
|
||||
|
||||
#### CLI Argument
|
||||
|
||||
Using docker-entrypoint.sh the following flags can be used to set gain and noise suppression:
|
||||
- `--mic-auto-gain`(ranges from 0-31)
|
||||
- `--mic-noise-suppression`(ranges from 0-4)
|
||||
|
||||
#### ENV file
|
||||
|
||||
You can add/edit these variables in the .env file to set gain and noise suppression:
|
||||
- `MIC_AUTO_GAIN="0"`
|
||||
- `MIC_NOISE_SUPPRESSION="0"`
|
||||
|
||||
|
||||
### Home Assistant Entity
|
||||
|
||||
LVA exposes two slider entities to change these gain and noise suppression from which you can edit the gain and noise suppression at runtime.
|
||||
|
||||
💡 **Note:** Setting the flag and ENV values to 0 turns them off and are not used.
|
||||
|
||||
💡 **Note:** Keep in mind that when the flags are set they will overwrite the previous value in the preferences file and also they will be overridden if the value is changed in Home Assistant(Also applies to the ENV file but the ENV file will always overwrite the last value on startup).
|
||||
@@ -176,6 +176,8 @@ Environment=PREFERENCES_FILE="/home/pi/linux-voice-assistant/preferences.json"
|
||||
# Environment=PORT="6053"
|
||||
# Environment=AUDIO_INPUT_DEVICE="default"
|
||||
# Environment=AUDIO_OUTPUT_DEVICE="default"
|
||||
# Environment=MIC_AUTO_GAIN="0"
|
||||
# Environment=MIC_NOISE_SUPPRESSION="0"
|
||||
# Environment=ENABLE_THINKING_SOUND="1"
|
||||
# Environment=WAKE_WORD_DIR="app/wakewords"
|
||||
# Environment=WAKE-MODEL="okay_nabu"
|
||||
@@ -255,6 +257,8 @@ The following variables can be configured in the `.env` or in the service file:
|
||||
| `PORT` | `6053` | API server port |
|
||||
| `AUDIO_INPUT_DEVICE` | Autodetected | Audio input device name |
|
||||
| `AUDIO_OUTPUT_DEVICE` | Autodetected | Audio output device name |
|
||||
| `MIC_AUTO_GAIN` | Add WebRTC Gain to Mic | 0 |
|
||||
| `MIC_NOISE_SUPPRESSION` | Add WebRTC Noise Suppresion to Mic | 0 |
|
||||
| `ENABLE_THINKING_SOUND` | false | Set to "1" to enable thinking sound |
|
||||
| `WAKE_WORD_DIR` | `app/wakewords` | Path to the wake word directory |
|
||||
| `WAKE_MODEL` | `okay_nabu` | Wake word model to use |
|
||||
|
||||
Reference in new issue
Block a user