Skip to content

Commit 8abd047

Browse files
authored
Rename raw audio files to .pcm (home-assistant#91879)
1 parent 1eef4af commit 8abd047

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

homeassistant/components/voip/voip.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
_TONE_DELAY = 0.2 # seconds before playing tone
3636
_MESSAGE_DELAY = 1.0 # seconds before playing "not configured" message
3737
_LOOP_DELAY = 2.0 # seconds before replaying not-configured message
38+
_RTP_AUDIO_SETTINGS = {"rate": 16000, "width": 2, "channels": 1, "sleep_ratio": 1.01}
3839
_LOGGER = logging.getLogger(__name__)
3940

4041

@@ -278,7 +279,7 @@ async def _send_media(self, media_id: str) -> None:
278279

279280
# Assume TTS audio is 16Khz 16-bit mono
280281
await self.hass.async_add_executor_job(
281-
partial(self.send_audio, audio_bytes, rate=16000, width=2, channels=1)
282+
partial(self.send_audio, audio_bytes, **_RTP_AUDIO_SETTINGS)
282283
)
283284

284285
async def _play_listening_tone(self) -> None:
@@ -293,16 +294,14 @@ async def _play_listening_tone(self) -> None:
293294
partial(
294295
self.send_audio,
295296
self._tone_bytes,
296-
rate=16000,
297-
width=2,
298-
channels=1,
299297
silence_before=_TONE_DELAY,
298+
**_RTP_AUDIO_SETTINGS,
300299
)
301300
)
302301

303302
def _load_tone(self) -> bytes:
304303
"""Load raw tone audio (16Khz, 16-bit mono)."""
305-
return (Path(__file__).parent / "tone.raw").read_bytes()
304+
return (Path(__file__).parent / "tone.pcm").read_bytes()
306305

307306

308307
class NotConfiguredRtpDatagramProtocol(RtpDatagramProtocol):
@@ -323,10 +322,11 @@ def on_chunk(self, audio_bytes: bytes) -> None:
323322
if self._audio_bytes is None:
324323
# 16Khz, 16-bit mono audio message
325324
self._audio_bytes = (
326-
Path(__file__).parent / "not_configured.raw"
325+
Path(__file__).parent / "not_configured.pcm"
327326
).read_bytes()
328327

329328
if self._audio_task is None:
329+
_LOGGER.info("HERE")
330330
self._audio_task = self.hass.async_create_background_task(
331331
self._play_message(),
332332
"voip_not_connected",
@@ -337,10 +337,8 @@ async def _play_message(self) -> None:
337337
partial(
338338
self.send_audio,
339339
self._audio_bytes,
340-
16000,
341-
2,
342-
1,
343340
silence_before=_MESSAGE_DELAY,
341+
**_RTP_AUDIO_SETTINGS,
344342
)
345343
)
346344

0 commit comments

Comments
 (0)