mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Send esphome tts_stream event after audio bytes are actually loaded into memory (#104448)
Send tts_stream event after audio bytes are actually loaded into memory
This commit is contained in:
parent
7fbf68fd11
commit
95c771e330
@ -301,10 +301,6 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
|
|||||||
if self.transport is None:
|
if self.transport is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.handle_event(
|
|
||||||
VoiceAssistantEventType.VOICE_ASSISTANT_TTS_STREAM_START, {}
|
|
||||||
)
|
|
||||||
|
|
||||||
extension, data = await tts.async_get_media_source_audio(
|
extension, data = await tts.async_get_media_source_audio(
|
||||||
self.hass,
|
self.hass,
|
||||||
media_id,
|
media_id,
|
||||||
@ -331,11 +327,17 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
|
|||||||
|
|
||||||
audio_bytes = wav_file.readframes(wav_file.getnframes())
|
audio_bytes = wav_file.readframes(wav_file.getnframes())
|
||||||
|
|
||||||
_LOGGER.debug("Sending %d bytes of audio", len(audio_bytes))
|
audio_bytes_size = len(audio_bytes)
|
||||||
|
|
||||||
|
_LOGGER.debug("Sending %d bytes of audio", audio_bytes_size)
|
||||||
|
|
||||||
|
self.handle_event(
|
||||||
|
VoiceAssistantEventType.VOICE_ASSISTANT_TTS_STREAM_START, {}
|
||||||
|
)
|
||||||
|
|
||||||
bytes_per_sample = stt.AudioBitRates.BITRATE_16 // 8
|
bytes_per_sample = stt.AudioBitRates.BITRATE_16 // 8
|
||||||
sample_offset = 0
|
sample_offset = 0
|
||||||
samples_left = len(audio_bytes) // bytes_per_sample
|
samples_left = audio_bytes_size // bytes_per_sample
|
||||||
|
|
||||||
while samples_left > 0:
|
while samples_left > 0:
|
||||||
bytes_offset = sample_offset * bytes_per_sample
|
bytes_offset = sample_offset * bytes_per_sample
|
||||||
|
Loading…
x
Reference in New Issue
Block a user