35
35
_TONE_DELAY = 0.2 # seconds before playing tone
36
36
_MESSAGE_DELAY = 1.0 # seconds before playing "not configured" message
37
37
_LOOP_DELAY = 2.0 # seconds before replaying not-configured message
38
+ _RTP_AUDIO_SETTINGS = {"rate" : 16000 , "width" : 2 , "channels" : 1 , "sleep_ratio" : 1.01 }
38
39
_LOGGER = logging .getLogger (__name__ )
39
40
40
41
@@ -278,7 +279,7 @@ async def _send_media(self, media_id: str) -> None:
278
279
279
280
# Assume TTS audio is 16Khz 16-bit mono
280
281
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 )
282
283
)
283
284
284
285
async def _play_listening_tone (self ) -> None :
@@ -293,16 +294,14 @@ async def _play_listening_tone(self) -> None:
293
294
partial (
294
295
self .send_audio ,
295
296
self ._tone_bytes ,
296
- rate = 16000 ,
297
- width = 2 ,
298
- channels = 1 ,
299
297
silence_before = _TONE_DELAY ,
298
+ ** _RTP_AUDIO_SETTINGS ,
300
299
)
301
300
)
302
301
303
302
def _load_tone (self ) -> bytes :
304
303
"""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 ()
306
305
307
306
308
307
class NotConfiguredRtpDatagramProtocol (RtpDatagramProtocol ):
@@ -323,10 +322,11 @@ def on_chunk(self, audio_bytes: bytes) -> None:
323
322
if self ._audio_bytes is None :
324
323
# 16Khz, 16-bit mono audio message
325
324
self ._audio_bytes = (
326
- Path (__file__ ).parent / "not_configured.raw "
325
+ Path (__file__ ).parent / "not_configured.pcm "
327
326
).read_bytes ()
328
327
329
328
if self ._audio_task is None :
329
+ _LOGGER .info ("HERE" )
330
330
self ._audio_task = self .hass .async_create_background_task (
331
331
self ._play_message (),
332
332
"voip_not_connected" ,
@@ -337,10 +337,8 @@ async def _play_message(self) -> None:
337
337
partial (
338
338
self .send_audio ,
339
339
self ._audio_bytes ,
340
- 16000 ,
341
- 2 ,
342
- 1 ,
343
340
silence_before = _MESSAGE_DELAY ,
341
+ ** _RTP_AUDIO_SETTINGS ,
344
342
)
345
343
)
346
344
0 commit comments