Revert "Use speex for noise suppression and auto gain" (#124620)

Revert "Use speex for noise suppression and auto gain (#124591)"

This reverts commit 592f60643a.
pull/124312/head
Paulus Schoutsen 2024-08-26 10:12:05 +02:00 committed by GitHub
parent 65216df3a5
commit 302ffe5e56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 8 additions and 39 deletions

View File

@ -5,7 +5,6 @@ from dataclasses import dataclass
import logging
from pymicro_vad import MicroVad
from pyspeex_noise import AudioProcessor
from .const import BYTES_PER_CHUNK
@ -42,8 +41,8 @@ class AudioEnhancer(ABC):
"""Enhance chunk of PCM audio @ 16Khz with 16-bit mono samples."""
class MicroVadSpeexEnhancer(AudioEnhancer):
"""Audio enhancer that runs microVAD and speex."""
class MicroVadEnhancer(AudioEnhancer):
"""Audio enhancer that just runs microVAD."""
def __init__(
self, auto_gain: int, noise_suppression: int, is_vad_enabled: bool
@ -51,24 +50,6 @@ class MicroVadSpeexEnhancer(AudioEnhancer):
"""Initialize audio enhancer."""
super().__init__(auto_gain, noise_suppression, is_vad_enabled)
self.audio_processor: AudioProcessor | None = None
# Scale from 0-4
self.noise_suppression = noise_suppression * -15
# Scale from 0-31
self.auto_gain = auto_gain * 300
if (self.auto_gain != 0) or (self.noise_suppression != 0):
self.audio_processor = AudioProcessor(
self.auto_gain, self.noise_suppression
)
_LOGGER.debug(
"Initialized speex with auto_gain=%s, noise_suppression=%s",
self.auto_gain,
self.noise_suppression,
)
self.vad: MicroVad | None = None
self.threshold = 0.5
@ -80,17 +61,12 @@ class MicroVadSpeexEnhancer(AudioEnhancer):
"""Enhance 10ms chunk of PCM audio @ 16Khz with 16-bit mono samples."""
is_speech: bool | None = None
assert len(audio) == BYTES_PER_CHUNK
if self.vad is not None:
# Run VAD
assert len(audio) == BYTES_PER_CHUNK
speech_prob = self.vad.Process10ms(audio)
is_speech = speech_prob > self.threshold
if self.audio_processor is not None:
# Run noise suppression and auto gain
audio = self.audio_processor.Process10ms(audio).audio
return EnhancedAudioChunk(
audio=audio, timestamp_ms=timestamp_ms, is_speech=is_speech
)

View File

@ -7,5 +7,5 @@
"integration_type": "system",
"iot_class": "local_push",
"quality_scale": "internal",
"requirements": ["pymicro-vad==1.0.1", "pyspeex-noise==1.0.0"]
"requirements": ["pymicro-vad==1.0.1"]
}

View File

@ -49,7 +49,7 @@ from homeassistant.util import (
)
from homeassistant.util.limited_size_dict import LimitedSizeDict
from .audio_enhancer import AudioEnhancer, EnhancedAudioChunk, MicroVadSpeexEnhancer
from .audio_enhancer import AudioEnhancer, EnhancedAudioChunk, MicroVadEnhancer
from .const import (
BYTES_PER_CHUNK,
CONF_DEBUG_RECORDING_DIR,
@ -589,7 +589,7 @@ class PipelineRun:
# Initialize with audio settings
if self.audio_settings.needs_processor and (self.audio_enhancer is None):
# Default audio enhancer
self.audio_enhancer = MicroVadSpeexEnhancer(
self.audio_enhancer = MicroVadEnhancer(
self.audio_settings.auto_gain_dbfs,
self.audio_settings.noise_suppression_level,
self.audio_settings.is_vad_enabled,

View File

@ -33,7 +33,7 @@ from homeassistant.components.assist_pipeline import (
)
from homeassistant.components.assist_pipeline.audio_enhancer import (
AudioEnhancer,
MicroVadSpeexEnhancer,
MicroVadEnhancer,
)
from homeassistant.components.assist_pipeline.vad import (
AudioBuffer,
@ -235,7 +235,7 @@ class PipelineRtpDatagramProtocol(RtpDatagramProtocol):
try:
# Wait for speech before starting pipeline
segmenter = VoiceCommandSegmenter(silence_seconds=self.silence_seconds)
audio_enhancer = MicroVadSpeexEnhancer(0, 0, True)
audio_enhancer = MicroVadEnhancer(0, 0, True)
chunk_buffer: deque[bytes] = deque(
maxlen=self.buffered_chunks_before_speech,
)

View File

@ -49,7 +49,6 @@ pymicro-vad==1.0.1
PyNaCl==1.5.0
pyOpenSSL==24.2.1
pyserial==3.5
pyspeex-noise==1.0.0
python-slugify==8.0.4
PyTurboJPEG==1.7.1
pyudev==0.24.1

View File

@ -2228,9 +2228,6 @@ pysoma==0.0.12
# homeassistant.components.spc
pyspcwebgw==0.7.0
# homeassistant.components.assist_pipeline
pyspeex-noise==1.0.0
# homeassistant.components.squeezebox
pysqueezebox==0.7.1

View File

@ -1782,9 +1782,6 @@ pysoma==0.0.12
# homeassistant.components.spc
pyspcwebgw==0.7.0
# homeassistant.components.assist_pipeline
pyspeex-noise==1.0.0
# homeassistant.components.squeezebox
pysqueezebox==0.7.1