Chime TTS - Play audio before/after TTS audio lag free

Sorry to keep spamming messages to this thread, but I found a fix to the delay between Sonos speakers in a multi-speaker setup. If you create a Speaker Group in the Sonos app and use that for the media device it it will work with no delays between speakers. Make sure you create the group in Sonos and not Home Assistant.

The only remaining issue for me is sometimes the volume does not revert to the original volume after the announcement is played.

I’m happy to hear you could resolve the timing issue. I will take a look at the volume level restore bug.

Do you have any additional information like the steps to reproduce the bug, or any relevant debug logs which might be helpful?

Here is a case starting from a fresh restart of Home Assistant. The same music was playing on a Sonos group of 3 speakers. I ran the announcement, it played fine, but the music did not restart.

2023-08-12 16:17:54.166 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Called -----
2023-08-12 16:17:54.167 DEBUG (MainThread) [custom_components.chime_tts] * entity_ids = ['media_player.whole_house_sonos']
2023-08-12 16:17:54.167 DEBUG (MainThread) [custom_components.chime_tts] * hass = <homeassistant.core.HomeAssistant object at 0x7f9f9aa5c050>
2023-08-12 16:17:54.167 DEBUG (MainThread) [custom_components.chime_tts] * chime_path = custom_components/chime_tts/mp3s/keys.mp3
2023-08-12 16:17:54.168 DEBUG (MainThread) [custom_components.chime_tts] * delay = 650.0
2023-08-12 16:17:54.168 DEBUG (MainThread) [custom_components.chime_tts] * message = Basement Door Open
2023-08-12 16:17:54.168 DEBUG (MainThread) [custom_components.chime_tts] * tts_platform = amazon_polly
2023-08-12 16:17:54.168 DEBUG (MainThread) [custom_components.chime_tts] * tts_playback_speed = 100.0
2023-08-12 16:17:54.168 DEBUG (MainThread) [custom_components.chime_tts] * volume_level = 0.4
2023-08-12 16:17:54.169 DEBUG (MainThread) [custom_components.chime_tts] * cache = True
2023-08-12 16:17:54.169 DEBUG (MainThread) [custom_components.chime_tts] * announce = True
2023-08-12 16:17:54.169 DEBUG (MainThread) [custom_components.chime_tts] ------
2023-08-12 16:17:54.169 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path
2023-08-12 16:17:54.170 DEBUG (MainThread) [custom_components.chime_tts] Attempting to retrieve generated mp3 file from cache
2023-08-12 16:17:54.170 DEBUG (MainThread) [custom_components.chime_tts] - async_get_cached_audio_data('2febd1b0fca5e1125ba2b05146b2afc3d07c7eb21b4bf49adaae201442dae2eb')
2023-08-12 16:17:54.170 DEBUG (MainThread) [custom_components.chime_tts] - Retrieving key/value from chime_tts storage:
2023-08-12 16:17:54.170 DEBUG (MainThread) [custom_components.chime_tts] - key: 2febd1b0fca5e1125ba2b05146b2afc3d07c7eb21b4bf49adaae201442dae2eb
2023-08-12 16:17:54.171 DEBUG (MainThread) [custom_components.chime_tts] - value: {'audio_path': '/media/sounds/temp/chime_tts/2p17vq7a.mp3', 'audio_duration': 3.934}
2023-08-12 16:17:54.171 DEBUG (MainThread) [custom_components.chime_tts] - Cached audio data found
2023-08-12 16:17:54.171 DEBUG (MainThread) [custom_components.chime_tts] Using previously generated mp3 saved in cache
2023-08-12 16:17:54.172 DEBUG (MainThread) [custom_components.chime_tts] - audio_dict = {'audio_path': '/media/sounds/temp/chime_tts/2p17vq7a.mp3', 'audio_duration': 3.934}
2023-08-12 16:17:54.172 DEBUG (MainThread) [custom_components.chime_tts] - async_set_volume_level("media_player.whole_house_sonos", 0.4)
2023-08-12 16:17:54.172 DEBUG (MainThread) [custom_components.chime_tts] - Seting volume_level of media player "media_player.whole_house_sonos" to: 0.4
2023-08-12 16:17:54.175 DEBUG (MainThread) [custom_components.chime_tts] - Volume set
2023-08-12 16:17:54.176 DEBUG (MainThread) [custom_components.chime_tts] Calling media_player.play_media service with data:
2023-08-12 16:17:54.176 DEBUG (MainThread) [custom_components.chime_tts] - media_content_id: media-source://media_source/local/sounds/temp/chime_tts/2p17vq7a.mp3
2023-08-12 16:17:54.176 DEBUG (MainThread) [custom_components.chime_tts] - media_content_type: music
2023-08-12 16:17:54.176 DEBUG (MainThread) [custom_components.chime_tts] - entity_id: ['media_player.whole_house_sonos']
2023-08-12 16:17:54.177 DEBUG (MainThread) [custom_components.chime_tts] - announce: True
2023-08-12 16:17:54.181 DEBUG (MainThread) [custom_components.chime_tts] ...media_player.play_media completed.
2023-08-12 16:17:54.181 DEBUG (MainThread) [custom_components.chime_tts] Waiting 3.934s for audio playback to complete...
2023-08-12 16:17:58.145 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Completed in 3978.261 ms -----

Here is my script for reference

service: chime_tts.say
data:
  end_chime_path: ""
  delay: 650
  final_delay: 0
  tts_playback_speed: 100
  volume_level: "{{ (states('input_text.tts_volume') | float) / 100 }}"
  message: "{{ message }}"
  announce: true
  tts_platform: amazon_polly
  cache: true
  chime_path: custom_components/chime_tts/mp3s/{{ clip }}
enabled: true
target:
  entity_id:
    - media_player.whole_house_sonos

When using a Speaker Group created in Sonos, playback of music does not resume after that announcement has played. I have reverted to including each Sonos speaker media_player entity independently.

@Nimrod, I saw a comment in one of my other threads that said you were going to start using the join and unjoin services to handle speaker groups. I would advise against this, in my experimentation this does not work.

@Nimrod_Dolev, t me know if you would rather have me send feedback on GitHub versus doing it here on these forums.

Thanks @theadlee, yes perhaps GitHub might be more appropriate.

@varyamereon the latest release (v0.7.0) no longer uses the REST API and instead uses internal service calls, which I hope takes care of your 500: Internal Server Error. Please upgrade and let me know if it is still happening for you.

@theadlee regarding 3 the issues you mentioned:

  1. The volume_level is restored using Home Assistant’s media_player.volume_set service. It could be that there’s a bug with this service, but if you could please provide debug logs from when it happens perhaps I could know more.
  2. The issue of the previously playing music failing to restart after the announcement is also controlled by Home Assistant (by passing the announce parameter in the data when calling media_player.play_media). Similarly, this is another Home Assistant service, but maybe the logs could be informative.
  3. I have added the option to join speakers together (with the media_player.join and media_player.unjoin services) in the latest release, v0.7.0. I understand this hasn’t worked for you in the past. I do not have supported speakers, so unfortunately I cannot test it out. Feel free to try it and let me know how it goes for you.

@Nimrod_Dolev for issues #1 and #2 I was using a Speaker Group created in Sonos when these issues were occuring. I have since moved away from that and am now sending all three media_players to the service. I have not seen these issues resurface yet. The only minor annoyance at this point is that there is a minor 200-300ms delay in one or more of the speakers during the announcement. All of the speakers do not play the announcement in sync.

I will not be able to test v0.7.0 for another 1.5 weeks as I am leaving home tomorrow.

They never will unless they’re joined in a group.

  • Joined speakers play content in unison.
  • Unjoined speakers play content separately.

Yes, i get that now.

@varyamereon please take a look at v0.7.2 which I have tested and confirmed to work with Nabu Casa’s Cloud TTS.

Hey @Nimrod_Dolev, that sure seems to work for me!! Thanks!

After some time I came back to it and I am surprised.
Everything works perfectly as expected with the NabuCasa cloud.
Thank you

I use squeezelite players and LMS server.
It would be nice to be able to resume playback after a message.
I tried but unfortunately it doesn’t work.
Anyone have an idea how to get this working?

Hi @Nimrod_Dolev,

Do you have any idea about this error?

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] Service call #0 was added to the queue.

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] Executing queued job #0

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Called -----

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * entity_ids = [‘media_player.lavandaria’]

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * hass = <homeassistant.core.HomeAssistant object at 0x7f05e2fe6a50>

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * delay = 450.0

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * message = Teste

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * tts_platform = google_translate

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * tts_playback_speed = 100.0

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * volume_level = -1.0

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * join_players = False

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * cache = False

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * announce = True

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * language = pt

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] * tld = pt

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] ------

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] Invalid audio filepath provided

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] async_request_tts_audio(hass, tts_platform=“google_translate”, message=“Teste”, cache=“False”, language=“pt”, tld=“pt”, gender=“None”, tts_playback_speed=“100.0”))

2023-08-25 17:12:32.672 DEBUG (MainThread) [custom_components.chime_tts] - Generating TTS audio…

2023-08-25 17:12:33.231 DEBUG (MainThread) [custom_components.chime_tts] - …TTS audio completed in 559.0880000000001 ms

2023-08-25 17:12:33.232 DEBUG (MainThread) [custom_components.chime_tts] - Final audio created:

2023-08-25 17:12:33.232 DEBUG (MainThread) [custom_components.chime_tts] - Duration = 0.864s

2023-08-25 17:12:33.232 DEBUG (MainThread) [custom_components.chime_tts] Creating final audio file

2023-08-25 17:12:33.232 DEBUG (MainThread) [custom_components.chime_tts] - Temp folder exists: /media/sounds/temp/chime_tts/

2023-08-25 17:12:33.232 DEBUG (MainThread) [custom_components.chime_tts] - Creating temporary mp3 file…

2023-08-25 17:12:33.232 DEBUG (MainThread) [custom_components.chime_tts] - temp_obj = <tempfile._TemporaryFileWrapper object at 0x7f0588cf3350>

2023-08-25 17:12:33.232 DEBUG (MainThread) [custom_components.chime_tts] - Filepath = ‘/media/sounds/temp/chime_tts/nvsbdgcu.mp3’

2023-08-25 17:12:33.270 DEBUG (MainThread) [custom_components.chime_tts] - File saved successfully

2023-08-25 17:12:33.270 DEBUG (MainThread) [custom_components.chime_tts] - audio_dict = {‘audio_path’: ‘/media/sounds/temp/chime_tts/nvsbdgcu.mp3’, ‘audio_duration’: 0.864}

2023-08-25 17:12:33.270 DEBUG (MainThread) [custom_components.chime_tts] Calling media_player.play_media service with data:

2023-08-25 17:12:33.270 DEBUG (MainThread) [custom_components.chime_tts] - media_content_type: music

2023-08-25 17:12:33.270 DEBUG (MainThread) [custom_components.chime_tts] - media_content_id: media-source://media_source/local/sounds/temp/chime_tts/nvsbdgcu.mp3

2023-08-25 17:12:33.270 DEBUG (MainThread) [custom_components.chime_tts] - announce: True

2023-08-25 17:12:33.270 DEBUG (MainThread) [custom_components.chime_tts] - entity_id: [‘media_player.lavandaria’]

2023-08-25 17:12:33.270 WARNING (MainThread) [custom_components.chime_tts] An error occurred: Unknown source directory.

2023-08-25 17:12:33.271 DEBUG (MainThread) [custom_components.chime_tts] Waiting 0.864s for audio playback to complete…

2023-08-25 17:12:34.135 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Completed in 1463.677 ms -----

2023-08-25 17:12:34.136 DEBUG (MainThread) [custom_components.chime_tts] Removing current queued service call.

2023-08-25 17:12:34.136 DEBUG (MainThread) [custom_components.chime_tts] Queue emptied.

Just wanted to say thank you, this is great, using it on a VLC player on a Mac, it’s working perfectly.

2 Likes

It looks like the audio file was generated successfully but for some reason the call to Home Assistant to play it failed to find the file on the filesystem:

An error occurred: Unknown source directory.

Are you able to play the file media-source://media_source/local/sounds/temp/chime_tts/nvsbdgcu.mp3 a standard play_media service call?

What setup do you have for your Home Assistant Instance?

Happy to hear it! Thank you :+1:

Is it possible to add edge TTS support?

Hi I tried several things to get the resume playback after TTS functionality working.

I play music like:

service: media_player.play_media
data:
  media_content_id: http://icecast.omroep.nl/radio2-bb-mp3
  media_content_type: audio/mp3
target:
  entity_id: media_player.google_nest_kantoor

And play the announcement like:

service: chime_tts.say
data:
  chime_path: custom_components/chime_tts/mp3s/bells.mp3
  message: This is a test.
  tts_platform: google_translate
  announce: true
target:
  entity_id: media_player.google_nest_kantoor

But music sadly does not resume.

Am I doing this wrong?