mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 15:27:08 +00:00
Enhance pipeline audio in the executor
enhance_chunk blocks the event loop for a bit every time its called because its CPU intensive
This commit is contained in:
parent
2cf3f2b243
commit
2dc113ba50
@ -575,8 +575,11 @@ class PipelineRun:
|
|||||||
_device_id: str | None = None
|
_device_id: str | None = None
|
||||||
"""Optional device id set during run start."""
|
"""Optional device id set during run start."""
|
||||||
|
|
||||||
|
_loop: asyncio.AbstractEventLoop | None = field(init=False, default=None)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Set language for pipeline."""
|
"""Set language for pipeline."""
|
||||||
|
self._loop = asyncio.get_running_loop()
|
||||||
self.language = self.pipeline.language or self.hass.config.language
|
self.language = self.pipeline.language or self.hass.config.language
|
||||||
|
|
||||||
# wake -> stt -> intent -> tts
|
# wake -> stt -> intent -> tts
|
||||||
@ -1284,6 +1287,7 @@ class PipelineRun:
|
|||||||
assert self.audio_enhancer is not None
|
assert self.audio_enhancer is not None
|
||||||
|
|
||||||
timestamp_ms = 0
|
timestamp_ms = 0
|
||||||
|
assert self._loop is not None
|
||||||
async for dirty_samples in audio_stream:
|
async for dirty_samples in audio_stream:
|
||||||
if self.audio_settings.volume_multiplier != 1.0:
|
if self.audio_settings.volume_multiplier != 1.0:
|
||||||
# Static gain
|
# Static gain
|
||||||
@ -1295,7 +1299,9 @@ class PipelineRun:
|
|||||||
for dirty_chunk in chunk_samples(
|
for dirty_chunk in chunk_samples(
|
||||||
dirty_samples, BYTES_PER_CHUNK, self.audio_chunking_buffer
|
dirty_samples, BYTES_PER_CHUNK, self.audio_chunking_buffer
|
||||||
):
|
):
|
||||||
yield self.audio_enhancer.enhance_chunk(dirty_chunk, timestamp_ms)
|
yield await self._loop.run_in_executor(
|
||||||
|
None, self.audio_enhancer.enhance_chunk, dirty_chunk, timestamp_ms
|
||||||
|
)
|
||||||
timestamp_ms += MS_PER_CHUNK
|
timestamp_ms += MS_PER_CHUNK
|
||||||
|
|
||||||
|
|
||||||
|
@ -708,7 +708,7 @@ async def test_wake_word_detection_aborted(
|
|||||||
assert process_events(events) == snapshot
|
assert process_events(events) == snapshot
|
||||||
|
|
||||||
|
|
||||||
def test_pipeline_run_equality(hass: HomeAssistant, init_components) -> None:
|
async def test_pipeline_run_equality(hass: HomeAssistant, init_components) -> None:
|
||||||
"""Test that pipeline run equality uses unique id."""
|
"""Test that pipeline run equality uses unique id."""
|
||||||
|
|
||||||
def event_callback(event):
|
def event_callback(event):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user