Fix VOIP blocking call in event loop (#168331)

This commit is contained in:
Jamin
2026-04-17 19:27:38 +00:00
committed by Franck Nijhof
parent 7bd0bc9c8a
commit 0af6a85049
+10 -5
View File
@@ -150,11 +150,6 @@ class PreRecordMessageProtocol(RtpDatagramProtocol):
if self.transport is None:
return
if self._audio_bytes is None:
# 16Khz, 16-bit mono audio message
file_path = Path(__file__).parent / self.file_name
self._audio_bytes = file_path.read_bytes()
if self._audio_task is None:
self._audio_task = self.hass.async_create_background_task(
self._play_message(),
@@ -162,6 +157,11 @@ class PreRecordMessageProtocol(RtpDatagramProtocol):
)
async def _play_message(self) -> None:
if self._audio_bytes is None:
_LOGGER.debug("Loading audio from file %s", self.file_name)
self._audio_bytes = await self._load_audio()
_LOGGER.debug("Read %s bytes", len(self._audio_bytes))
await self.hass.async_add_executor_job(
partial(
self.send_audio,
@@ -175,3 +175,8 @@ class PreRecordMessageProtocol(RtpDatagramProtocol):
# Allow message to play again
self._audio_task = None
async def _load_audio(self) -> bytes:
# 16Khz, 16-bit mono audio message
file_path = Path(__file__).parent / self.file_name
return await self.hass.async_add_executor_job(file_path.read_bytes)