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

thanks @Nimrod_Dolev for the feedback.

Debug enable: (I removed some keys)

10:27:45.340 WARNING (MainThread) [custom_components.chime_tts] Audio filepath does not exist: “/config/tts/d904ff352873fdb2ed2c0422810cb61fb5c313b0_pt_693225a70b_google_translate.mp3”
2023-06-22 10:27:45.343 ERROR (MainThread) [custom_components.chime_tts] Unable to create audio for playback
2023-06-22 10:30:47.420 DEBUG (MainThread) [custom_components.chime_tts] async_say(service)
2023-06-22 10:30:47.420 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path(params={‘hass’: <homeassistant.core.HomeAssistant object at 0x7fe7c5a35650>, ‘chime_path’: ‘custom_components/chime_tts/mp3s/bells.mp3’, ‘end_chime_path’: ‘’, ‘delay’: 450.0, ‘tts_platform’: ‘google_translate’, ‘message’: ‘teste um dois tres’, ‘language’: ‘pt’, ‘tld’: ‘pt’, ‘gender’: ‘female’})
2023-06-22 10:30:47.420 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path(“custom_components/chime_tts/mp3s/bells.mp3”, 0, audio)
2023-06-22 10:30:47.423 DEBUG (MainThread) [custom_components.chime_tts] Retrieving audio from path: “custom_components/chime_tts/mp3s/bells.mp3”…
2023-06-22 10:30:47.763 DEBUG (MainThread) [custom_components.chime_tts] - …audio retrieved successfully
2023-06-22 10:30:47.764 DEBUG (MainThread) [custom_components.chime_tts] async_get_tts_cache_path(‘Key removed’)
2023-06-22 10:30:47.769 DEBUG (MainThread) [custom_components.chime_tts] - TTS file does not exist in cache.
2023-06-22 10:30:47.769 DEBUG (MainThread) [custom_components.chime_tts] async_request_tts_audio_filepath(hass, tts_platform=“google_translate”, message=“teste um dois tres”, language=“pt”, tld=“pt”, gender=“female”)
2023-06-22 10:30:47.770 DEBUG (MainThread) [custom_components.chime_tts] Requesting TTS audio:
2023-06-22 10:30:47.770 DEBUG (MainThread) [custom_components.chime_tts] * url = http://192.168.4.25:8123/api/tts_get_url
2023-06-22 10:30:47.770 DEBUG (MainThread) [custom_components.chime_tts] * headers = {‘Authorization’: ‘Bearer Key removed’, ‘Content-Type’: ‘application/json’}
2023-06-22 10:30:47.770 DEBUG (MainThread) [custom_components.chime_tts] * data = {“message”: “teste um dois tres”, “platform”: “google_translate”, “cache”: true, “language”: “pt”, “options”: {“tld”: “pt”}}
2023-06-22 10:30:47.770 DEBUG (MainThread) [custom_components.chime_tts] * timeout = 10
2023-06-22 10:30:48.090 DEBUG (MainThread) [custom_components.chime_tts] - Repsonse status_code: “200”
2023-06-22 10:30:48.090 DEBUG (MainThread) [custom_components.chime_tts] - Repsonse received: “{“url”:“http://192.168.4.25:8123/api/tts_proxy/deeddf06306e52f24574a76e7a18303d1d36120f_pt_693225a70b_google_translate.mp3",“path”:"/api/tts_proxy/deeddf06306e52f24574a76e7a18303d1d36120f_pt_693225a70b_google_translate.mp3"}"
2023-06-22 10:30:48.090 DEBUG (MainThread) [custom_components.chime_tts] - REST API request to /api/tts_get_url returned audio path: ‘/config/tts/deeddf06306e52f24574a76e7a18303d1d36120f_pt_693225a70b_google_translate.mp3’
2023-06-22 10:30:48.090 DEBUG (MainThread) [custom_components.chime_tts] Saving to chime_tts storage:
2023-06-22 10:30:48.090 DEBUG (MainThread) [custom_components.chime_tts] key: “Key removed”
2023-06-22 10:30:48.090 DEBUG (MainThread) [custom_components.chime_tts] value: “/config/tts/deeddf06306e52f24574a76e7a18303d1d36120f_pt_693225a70b_google_translate.mp3”
2023-06-22 10:30:48.366 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path(”/config/tts/deeddf06306e52f24574a76e7a18303d1d36120f_pt_693225a70b_google_translate.mp3”, 450.0, audio)
2023-06-22 10:30:48.366 WARNING (MainThread) [custom_components.chime_tts] Audio filepath does not exist: “/config/tts/deeddf06306e52f24574a76e7a18303d1d36120f_pt_693225a70b_google_translate.mp3”
2023-06-22 10:30:48.368 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("", 450.0, audio)
2023-06-22 10:30:48.368 DEBUG (MainThread) [custom_components.chime_tts] No filepath provided
2023-06-22 10:30:48.368 DEBUG (MainThread) [custom_components.chime_tts] - Final audio created with duration = 0.944s
2023-06-22 10:30:48.901 DEBUG (MainThread) [custom_components.chime_tts] - async_set_volume_level(“media_player.homepod_mini”, 0.58)
2023-06-22 10:30:48.901 DEBUG (MainThread) [custom_components.chime_tts] - Seting volume_level of media player “media_player.homepod_mini” to: 0.58
2023-06-22 10:30:49.044 DEBUG (MainThread) [custom_components.chime_tts] - async_set_volume_level: completed
2023-06-22 10:30:49.044 DEBUG (MainThread) [custom_components.chime_tts] Playing media…
2023-06-22 10:30:49.044 DEBUG (MainThread) [custom_components.chime_tts] - audio_path = “/tmp/tmpn0xd5utw.mp3”
2023-06-22 10:30:49.044 DEBUG (MainThread) [custom_components.chime_tts] - entity_id = “media_player.homepod_mini”
2023-06-22 10:30:59.045 DEBUG (MainThread) [custom_components.chime_tts] …media finished playback:
2023-06-22 10:30:59.991 DEBUG (MainThread) [custom_components.chime_tts] - async_set_volume_level(“media_player.homepod_mini”, 0.47)
2023-06-22 10:30:59.991 DEBUG (MainThread) [custom_components.chime_tts] - Seting volume_level of media player “media_player.homepod_mini” to: 0.47

Thanks @juaurodri for supplying the logs.

It looks like the TTS request completes successfully and provides the file path to the .mp3 file, but when Chime TTS tries to access it, it fails to load.

  1. Do you hear the chime sound from your media player?

  2. To rule out any issue with the .mp3 file, can you please try to open the .mp3 path directly in your browser?
    http://192.168.4.25:8123/api/tts_proxy/deeddf06306e52f24574a76e7a18303d1d36120f_pt_693225a70b_google_translate.mp3
    If it loads normally from the browser I will add a catch to use the full URL instead of the local path.

  3. Could you please share with me which installation type you have for your Home Assistant instance (Raspberry Pi / docker / etc.)?

yeah @Nimrod_Dolev ,

1 - yes
2 - no, because the config/tts folder didn’t have the file
3 - docker

Its working now, I tried a normal tts.google and it saved the .mp3 in the tts folder, after that the chimeTTS started working ( with .mp3 file in the tts folder)

Strange behavior

But thanks!
looks great, I just need to confirm the announce feature works, if so, it’s perfect

@Nimrod_Dolev I’m seeing a similar issue - no errors in my logs but no audio plays from my media players when using the chime_tts service call.

  1. I don’t hear any sound at all from my media player when executing this service.
  2. The .mp3 does play when I navigate to <my_hass_hostname>/api/tts_proxy/d3486ae9136e7856bc42212385ea797094475802_en_-_google_translate.mp3
  3. I’m running HassOS on proxmox

Playing local media files on these media players using the play_media service call works fine.

Here’s the logs after executing the service:

2023-07-12 16:41:46.658 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Called -----
2023-07-12 16:41:46.658 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path(params={'hass': <homeassistant.core.HomeAssistant object at 0x7f12d52c1610>, 'chime_path': 'custom_components/chime_tts/mp3s/bells.mp3', 'end_chime_path': '', 'delay': 450.0, 'tts_platform': 'google_translate', 'tts_playback_speed': 100.0, 'message': 'Hello world!', 'language': None, 'tld': None, 'gender': None})
2023-07-12 16:41:46.658 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("custom_components/chime_tts/mp3s/bells.mp3", 0, audio)
2023-07-12 16:41:46.658 DEBUG (MainThread) [custom_components.chime_tts] Retrieving audio from path: "custom_components/chime_tts/mp3s/bells.mp3"...
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts]  - ...audio retrieved successfully
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts] async_get_tts_cache_path('Z29vZ2xlX3RyYW5zbGF0ZS1IZWxsbyB3b3JsZCE=')
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts] Retrieving key/value from chime_tts storage:
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts] key: Z29vZ2xlX3RyYW5zbGF0ZS1IZWxsbyB3b3JsZCE=
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts] value: /config/tts/d3486ae9136e7856bc42212385ea797094475802_en_-_google_translate.mp3
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts]  - async_get_tts_cache_path('Z29vZ2xlX3RyYW5zbGF0ZS1IZWxsbyB3b3JsZCE=') returned value: '/config/tts/d3486ae9136e7856bc42212385ea797094475802_en_-_google_translate.mp3'
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts]  - Using cached TTS mp3 filepath
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("/config/tts/d3486ae9136e7856bc42212385ea797094475802_en_-_google_translate.mp3", 450.0, audio)
2023-07-12 16:41:46.750 DEBUG (MainThread) [custom_components.chime_tts] Retrieving audio from path: "/config/tts/d3486ae9136e7856bc42212385ea797094475802_en_-_google_translate.mp3"...
2023-07-12 16:41:46.839 DEBUG (MainThread) [custom_components.chime_tts]  - ...audio retrieved successfully
2023-07-12 16:41:46.840 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("", 450.0, audio)
2023-07-12 16:41:46.840 DEBUG (MainThread) [custom_components.chime_tts] No filepath provided
2023-07-12 16:41:46.840 DEBUG (MainThread) [custom_components.chime_tts]  - Final audio created with duration = 2.666s
2023-07-12 16:41:46.907 DEBUG (MainThread) [custom_components.chime_tts]  - async_set_volume_level("media_player.kitchen", -1.0)
2023-07-12 16:41:46.907 DEBUG (MainThread) [custom_components.chime_tts]  - async_set_volume_level: Skipped setting volume
2023-07-12 16:41:46.907 DEBUG (MainThread) [custom_components.chime_tts] Playing media...
2023-07-12 16:41:46.907 DEBUG (MainThread) [custom_components.chime_tts]   - audio_path = "/tmp/tmpbqk3muo1.mp3"
2023-07-12 16:41:46.907 DEBUG (MainThread) [custom_components.chime_tts]   - entity_id = "media_player.kitchen"

@jreed509 If you are able to play other local media files on this player using the play_media service then I don’t see why it shouldn’t also work for chime_tts. Behind the scenes it uses the same play_media service to play the generated mp3.

You’ve tested the mp3 generated from chime_tts in your browser, so it’s not as issue with the file, but have you tried playing it on your player using HA’s play_media service? Eg:

service: media_player.play_media
data:
  media_content_id: <my_hass_hostname>/api/tts_proxy/d3486ae9136e7856bc42212385ea797094475802_en_-_google_translate.mp3
  media_content_type: music
target:
  entity_id: media_player.kitchen

Hmm yep that seems to be the issue. Calling that service doesn’t result in any sound output and no errors in the logs. Any thoughts on why that would be the case?

I can play other urls with the play_media service. For example setting media_content_id to media-source://media_source/local/local/doorbell-short.mp3 or media-source://tts/tts.piper?message=Hello+World&language=en-us&voice=en-us-amy-low works fine.

I’m running my HA instance on an Raspberry Pi, and I haven’t had the same issue, so maybe there’s a difference when running on proxmox? Perhaps the file path of the temporary mp3 file generated by chime_tts is the issue.

Try calling the play_media service with the temp mp3 file path included in the debug message. If it doesn’t play, perhaps try a few different options for the root folder, maybe that’s the key?

Calling play_media with the temp mp3 file path didn’t work either. As far as I can tell the play_media service doesn’t work for any urls outside of the media_browser or that are accessible from browser.

Is the .mp3 file in the /tmp directory accessible from the browser on your Pi?

I think the issue has to do with playing media files not located inside a media folder. I am working on a fix and will let you know when it will be available.

I released a new version, v0.5.0, that includes a change of the generated audio path to the media folder. Can you please test it and let me know if solves the problem?

Yep, v0.5.0 seemed to fix it for me. Thanks!!

Hi @kartcon, @juaurodri & @Jizzay1 The latest version, v0.5.0, should fix the playback issue you experienced earlier :+1:

1 Like

@Nimrod_Dolev actually after some more testing, this only seems to be working on Homepods for me now. Using v0.5.0 on my sonos or cast devices results in the same issue as before.

With v0.5.0, I do see the audio files being created in the media browser and I can play them fine to any speaker from there. It looks like the url used by the media browser is media-source://media_source/local/sounds/temp/chime_tts/0qi51w0j.mp3 which appears to be different from what is being used by chime_tts based on the logs.

@jreed509, Thanks for the feedback. I released a hotfix, v0.5.1, which hopefully addresses the problem. I only have a HomePod device, so I can’t test the fix myself. Please update to the new version and let me know if it works for you.

Unfortunately v0.5.1 doesn’t fix the issue for me either. Very strange since copying the url generated from the debug logs and using it in the play_media service works fine - it just doesn’t play when calling the chime_tts.say service to any device other than homepods

I also cannot play media on my player but i get a different error message. I also tried your 0.5.1 update. I am also using google translate platform. Here is my log:

023-07-18 01:36:57.162 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Called -----
2023-07-18 01:36:57.162 INFO (MainThread) [custom_components.chime_tts] Turning on media player entity: "media_player.office_speaker"
2023-07-18 01:36:57.165 WARNING (MainThread) [custom_components.chime_tts] Media player entity "media_player.office_speaker" does not have attributes
2023-07-18 01:36:57.165 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path(params={'hass': <homeassistant.core.HomeAssistant object at 0x7f4b0e13f350>, 'chime_path': '', 'end_chime_path': '', 'delay': 450.0, 'tts_platform': 'google_translate', 'tts_playback_speed': 100.0, 'cache': 'False', 'message': 'test', 'language': None, 'tld': None, 'gender': None})
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] Attempting to retrieve generated mp3 file from cache
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] async_get_cache_path('59a8723d8d41df3dea405bfd53affb71306315d438d9535db367daa0e9bd0ab8')
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts]  - File does not exist in cache.
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] No previously generated mp3 file found
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("", 0, audio)
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] No filepath provided
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] async_get_cache_path('4fe4096bec096563583a4523ba3dc4cfc4ecc249a65f2755c17c2cb604e62b40')
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] Retrieving key/value from chime_tts storage:
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] key: 4fe4096bec096563583a4523ba3dc4cfc4ecc249a65f2755c17c2cb604e62b40
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] value: /config/tts/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_en_-_google_translate.mp3
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts]  - async_get_cache_path('4fe4096bec096563583a4523ba3dc4cfc4ecc249a65f2755c17c2cb604e62b40') returned value: '/config/tts/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_en_-_google_translate.mp3'
2023-07-18 01:36:57.166 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("/config/tts/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_en_-_google_translate.mp3", 450.0, audio)
2023-07-18 01:36:57.166 WARNING (MainThread) [custom_components.chime_tts] Audio filepath does not exist: "/config/tts/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_en_-_google_translate.mp3"
2023-07-18 01:36:57.167 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("", 450.0, audio)
2023-07-18 01:36:57.167 DEBUG (MainThread) [custom_components.chime_tts] No filepath provided
2023-07-18 01:36:57.167 ERROR (MainThread) [custom_components.chime_tts] Unable to create audio for playback

I have checked the /config/tts directory and it does not have any cached file in there after running the say command. My devices are google home minis and ive tried a bose with built in google home as well

I can also use the tts.google_say service just fine

@Maxcodesthings & @jreed509 thank you both for your feedback.
Can you please try the new version, v0.5.2, and let me know if there’s any change?

I have also just updated to version v0.5.2 and trying to get this to work. The MP3 files are being generated in the TTS folder, but i’m unable to hear the message through the mediaplayer. When using the “tts.google_translate_say” service I can hear the message just fine.

Not sure what is going on, do you have any idea?

@Bramus - It would be helpful if you could please share your debug log messages in order to better understand what’s going on:

  1. Enable debugging for Chime TTS:
service: logger.set_level
data:
  custom_components.chime_tts: debug
  1. Run the chime_tts.say service again.

  2. Open your log messages for Chime TTS: [YOUR_HA_HOSTNAME]:8123/config/logs?filter=chime_tts

  3. Press the LOAD FULL LOGS button.

  4. Send a reply here with the log messages.

Can you also please share your HA setup and which type of media_player device are you using?

@Nimrod_Dolev I have the following in the log file: The tada.mp3 file does exist, except i’m running Home Assistant Core in an virtual environment. The file that it refers to (7944…mp3" does exist, so it looks like with the paths something is not working in an venc / HA Core setup?


Logger: custom_components.chime_tts
Source: custom_components/chime_tts/__init__.py:142
Integration: Chime TTS (documentation, issues)
First occurred: 13:50:20 (3 occurrences)
Last logged: 13:50:20

Audio filepath does not exist: "custom_components/chime_tts/mp3s/tada.mp3"
Audio filepath does not exist: "/config/tts/7944c5f87770f2710f409032dd78d78b3aeea91d_nl_-_google_translate.mp3"
Audio filepath does not exist: "custom_components/chime_tts/mp3s/bright.mp3"