Revert "Use speex for noise suppression and auto gain" (#124620)
Revert "Use speex for noise suppression and auto gain (#124591)"
This reverts commit 592f60643a
.
This commit is contained in:
parent
65216df3a5
commit
302ffe5e56
7 changed files with 8 additions and 39 deletions
|
@ -5,7 +5,6 @@ from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pymicro_vad import MicroVad
|
from pymicro_vad import MicroVad
|
||||||
from pyspeex_noise import AudioProcessor
|
|
||||||
|
|
||||||
from .const import BYTES_PER_CHUNK
|
from .const import BYTES_PER_CHUNK
|
||||||
|
|
||||||
|
@ -42,8 +41,8 @@ class AudioEnhancer(ABC):
|
||||||
"""Enhance chunk of PCM audio @ 16Khz with 16-bit mono samples."""
|
"""Enhance chunk of PCM audio @ 16Khz with 16-bit mono samples."""
|
||||||
|
|
||||||
|
|
||||||
class MicroVadSpeexEnhancer(AudioEnhancer):
|
class MicroVadEnhancer(AudioEnhancer):
|
||||||
"""Audio enhancer that runs microVAD and speex."""
|
"""Audio enhancer that just runs microVAD."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, auto_gain: int, noise_suppression: int, is_vad_enabled: bool
|
self, auto_gain: int, noise_suppression: int, is_vad_enabled: bool
|
||||||
|
@ -51,24 +50,6 @@ class MicroVadSpeexEnhancer(AudioEnhancer):
|
||||||
"""Initialize audio enhancer."""
|
"""Initialize audio enhancer."""
|
||||||
super().__init__(auto_gain, noise_suppression, is_vad_enabled)
|
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.vad: MicroVad | None = None
|
||||||
self.threshold = 0.5
|
self.threshold = 0.5
|
||||||
|
|
||||||
|
@ -80,17 +61,12 @@ class MicroVadSpeexEnhancer(AudioEnhancer):
|
||||||
"""Enhance 10ms chunk of PCM audio @ 16Khz with 16-bit mono samples."""
|
"""Enhance 10ms chunk of PCM audio @ 16Khz with 16-bit mono samples."""
|
||||||
is_speech: bool | None = None
|
is_speech: bool | None = None
|
||||||
|
|
||||||
assert len(audio) == BYTES_PER_CHUNK
|
|
||||||
|
|
||||||
if self.vad is not None:
|
if self.vad is not None:
|
||||||
# Run VAD
|
# Run VAD
|
||||||
|
assert len(audio) == BYTES_PER_CHUNK
|
||||||
speech_prob = self.vad.Process10ms(audio)
|
speech_prob = self.vad.Process10ms(audio)
|
||||||
is_speech = speech_prob > self.threshold
|
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(
|
return EnhancedAudioChunk(
|
||||||
audio=audio, timestamp_ms=timestamp_ms, is_speech=is_speech
|
audio=audio, timestamp_ms=timestamp_ms, is_speech=is_speech
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
"integration_type": "system",
|
"integration_type": "system",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"quality_scale": "internal",
|
"quality_scale": "internal",
|
||||||
"requirements": ["pymicro-vad==1.0.1", "pyspeex-noise==1.0.0"]
|
"requirements": ["pymicro-vad==1.0.1"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ from homeassistant.util import (
|
||||||
)
|
)
|
||||||
from homeassistant.util.limited_size_dict import LimitedSizeDict
|
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 (
|
from .const import (
|
||||||
BYTES_PER_CHUNK,
|
BYTES_PER_CHUNK,
|
||||||
CONF_DEBUG_RECORDING_DIR,
|
CONF_DEBUG_RECORDING_DIR,
|
||||||
|
@ -589,7 +589,7 @@ class PipelineRun:
|
||||||
# Initialize with audio settings
|
# Initialize with audio settings
|
||||||
if self.audio_settings.needs_processor and (self.audio_enhancer is None):
|
if self.audio_settings.needs_processor and (self.audio_enhancer is None):
|
||||||
# Default audio enhancer
|
# Default audio enhancer
|
||||||
self.audio_enhancer = MicroVadSpeexEnhancer(
|
self.audio_enhancer = MicroVadEnhancer(
|
||||||
self.audio_settings.auto_gain_dbfs,
|
self.audio_settings.auto_gain_dbfs,
|
||||||
self.audio_settings.noise_suppression_level,
|
self.audio_settings.noise_suppression_level,
|
||||||
self.audio_settings.is_vad_enabled,
|
self.audio_settings.is_vad_enabled,
|
||||||
|
|
|
@ -33,7 +33,7 @@ from homeassistant.components.assist_pipeline import (
|
||||||
)
|
)
|
||||||
from homeassistant.components.assist_pipeline.audio_enhancer import (
|
from homeassistant.components.assist_pipeline.audio_enhancer import (
|
||||||
AudioEnhancer,
|
AudioEnhancer,
|
||||||
MicroVadSpeexEnhancer,
|
MicroVadEnhancer,
|
||||||
)
|
)
|
||||||
from homeassistant.components.assist_pipeline.vad import (
|
from homeassistant.components.assist_pipeline.vad import (
|
||||||
AudioBuffer,
|
AudioBuffer,
|
||||||
|
@ -235,7 +235,7 @@ class PipelineRtpDatagramProtocol(RtpDatagramProtocol):
|
||||||
try:
|
try:
|
||||||
# Wait for speech before starting pipeline
|
# Wait for speech before starting pipeline
|
||||||
segmenter = VoiceCommandSegmenter(silence_seconds=self.silence_seconds)
|
segmenter = VoiceCommandSegmenter(silence_seconds=self.silence_seconds)
|
||||||
audio_enhancer = MicroVadSpeexEnhancer(0, 0, True)
|
audio_enhancer = MicroVadEnhancer(0, 0, True)
|
||||||
chunk_buffer: deque[bytes] = deque(
|
chunk_buffer: deque[bytes] = deque(
|
||||||
maxlen=self.buffered_chunks_before_speech,
|
maxlen=self.buffered_chunks_before_speech,
|
||||||
)
|
)
|
||||||
|
|
|
@ -49,7 +49,6 @@ pymicro-vad==1.0.1
|
||||||
PyNaCl==1.5.0
|
PyNaCl==1.5.0
|
||||||
pyOpenSSL==24.2.1
|
pyOpenSSL==24.2.1
|
||||||
pyserial==3.5
|
pyserial==3.5
|
||||||
pyspeex-noise==1.0.0
|
|
||||||
python-slugify==8.0.4
|
python-slugify==8.0.4
|
||||||
PyTurboJPEG==1.7.1
|
PyTurboJPEG==1.7.1
|
||||||
pyudev==0.24.1
|
pyudev==0.24.1
|
||||||
|
|
|
@ -2228,9 +2228,6 @@ pysoma==0.0.12
|
||||||
# homeassistant.components.spc
|
# homeassistant.components.spc
|
||||||
pyspcwebgw==0.7.0
|
pyspcwebgw==0.7.0
|
||||||
|
|
||||||
# homeassistant.components.assist_pipeline
|
|
||||||
pyspeex-noise==1.0.0
|
|
||||||
|
|
||||||
# homeassistant.components.squeezebox
|
# homeassistant.components.squeezebox
|
||||||
pysqueezebox==0.7.1
|
pysqueezebox==0.7.1
|
||||||
|
|
||||||
|
|
|
@ -1782,9 +1782,6 @@ pysoma==0.0.12
|
||||||
# homeassistant.components.spc
|
# homeassistant.components.spc
|
||||||
pyspcwebgw==0.7.0
|
pyspcwebgw==0.7.0
|
||||||
|
|
||||||
# homeassistant.components.assist_pipeline
|
|
||||||
pyspeex-noise==1.0.0
|
|
||||||
|
|
||||||
# homeassistant.components.squeezebox
|
# homeassistant.components.squeezebox
|
||||||
pysqueezebox==0.7.1
|
pysqueezebox==0.7.1
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue