mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Revert "Revert "Use speex for noise suppression and auto gain"" (#124637)
Revert "Revert "Use speex for noise suppression and auto gain" (#124620)" This reverts commit 302ffe5e56488f2f139686d375e5c82339304c87.
This commit is contained in:
parent
743df84569
commit
1aa0dbdaf5
@ -5,6 +5,7 @@ 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
|
||||||
|
|
||||||
@ -41,8 +42,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 MicroVadEnhancer(AudioEnhancer):
|
class MicroVadSpeexEnhancer(AudioEnhancer):
|
||||||
"""Audio enhancer that just runs microVAD."""
|
"""Audio enhancer that runs microVAD and speex."""
|
||||||
|
|
||||||
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
|
||||||
@ -50,6 +51,24 @@ class MicroVadEnhancer(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
|
||||||
|
|
||||||
@ -61,12 +80,17 @@ class MicroVadEnhancer(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"]
|
"requirements": ["pymicro-vad==1.0.1", "pyspeex-noise==1.0.0"]
|
||||||
}
|
}
|
||||||
|
@ -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, MicroVadEnhancer
|
from .audio_enhancer import AudioEnhancer, EnhancedAudioChunk, MicroVadSpeexEnhancer
|
||||||
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 = MicroVadEnhancer(
|
self.audio_enhancer = MicroVadSpeexEnhancer(
|
||||||
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,
|
||||||
MicroVadEnhancer,
|
MicroVadSpeexEnhancer,
|
||||||
)
|
)
|
||||||
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 = MicroVadEnhancer(0, 0, True)
|
audio_enhancer = MicroVadSpeexEnhancer(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,6 +49,7 @@ 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,6 +2228,9 @@ 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,6 +1782,9 @@ 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…
x
Reference in New Issue
Block a user