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

Wow!
this is amazing :blush: and thank you so much for the quick updates!

service: chime_tts.say
target:
  entity_id: media_player.wohnzimmer
data:
  tts_platform: amazon_polly
  announce: true
  message:
    - type: chime
      path: /media/notify/1_slow.mp3
      audio_conversion: "-filter:a volume=.25"
    - type: tts
      message: Diese Nachricht ist für Nim. Vielen Dank für das schnelle turnaround!
      delay: -3800
      audio_conversion: "-filter:a volume=5"
  volume_level: .4

works great so far!

An additional Idea:
also saving message array objects as a presets, with audio conversion filter, delay, and other options.

as in my example above, /media/notify/1_slow.mp3 with a delay of -3800 and volume of .25 works great, for the chime 6_ok a delay of -5800 is good.
Both are bells/chimes that have a very long sustain that fades out, you can find them here: 1.37 MB folder on MEGA they are all from notificationsounds.com albeit renamed )

And saving these with a preset would be a timesaver! (I could probably do that with a custom script for now)

Happy to help :+1: i’m happy it’s working for you!

Overlay

I think I the overlay feature needs to be defined as a parameter of the first segment, and not the second, seeing as it is associated with the chime, and not the TTS audio. Also, I feel it would be easier to understand if it were added as a separate parameter to the delay parameter, Eg:

service: chime_tts.say
target:
  entity_id: media_player.wohnzimmer
data:
  tts_platform: amazon_polly
  announce: true
  message:
    - type: chime
      path: /media/notify/1_slow.mp3
      audio_conversion: "-filter:a volume=.25"
      overlay: 3800 # <-- Overlay with the next mesage segment
    - type: tts
      message: Diese Nachricht ist für Lukas. Vielen Dank für den tollen Vorschlag!
      audio_conversion: "-filter:a volume=5"

Message Segment Presets

I really like the idea of defining preset message segments. You’re right in that you can achieve the same thing with scripts, but the whole idea of Chime TTS is to provide additional audio notifications functionality easily.

In addition to chime segments, the segment presets would also be useful for TTS segments. You could configure a TTS segment preset for each TTS platform (with the tts_platform, tts_playback_speed, options parameters, etc.) allowing you to only have to set the message string.

I think a good way to implement the feature would be to add a new multiline textfield to the Chime TTS configuration page, “Custom Segments”, which would hold a YAML array of N “chime” and/or “tts” segment object types, with the relevant parameter values. Each object would also have a unique “name” value which would serve as a reference when used in service calls to chime_tts.say and chime_tts.say_url.

An example of the “Custom Segments” textfield value:

- type: chime
  path: /media/chimes/my_chime.mp3
  audio_conversion: "-filter:a volume=1.5"
  overlay: 3875
  name: my_chime # <-- Reference ID to include in service calls

- type: tts
  message: Replace this string when calling the service
  tts_platform: amazon_polly
  ttts_playback_speed: 115
  name: amazon_polly # <-- Reference ID to include in service calls

great ideas!
I agree the overlay should be part of the chime. I like verbose names, may I suggest overlayStartMills

regarding the segments (this might just repeat what you were saying, not sure)
the segment presets could be used like templates, referencing a preset would take all of its values and overwrite with any given value. eg preset.update(given_values)
https://docs.python.org/2/library/stdtypes.html#dict.update

- my_chime: # <-- Reference ID as Dict Key
    type: chime
    path: /media/chimes/my_chime.mp3
    audio_conversion: "-filter:a volume=1.5"
    overlayStartMills: 3875
service: chime_tts.say
data:
  message:
    - preset: my_chime
      # implies values defined above
      #  type: chime
      #  path: /media/chimes/my_chime.mp3
      #  audio_conversion: "-filter:a volume=1.5"
      #  overlayStartMills: 3875
      path: /media/chimes/my_other_chime.mp3 # overwrites chime from preset

Yes, this is what I had in mind as well :+1:

1 Like

Unfortunately the configuration page for integrations has quite limited UI capabilities. Currently it is not possible to add a multiline textarea to add segment presets as a YAML array string.

I have thought up the following ways to implement segment presets, none of which I like :man_facepalming:

1. Add individual segment preset textfields to the configuration

Without multiline textareas in the configuration page, I could instead add single line textfields, each defining a single segment preset YAML object, eg:
- my_chime:\n type: chime\n path: /media/chimes/my_chime.mp3\n audio_conversion: "-filter:a volume=1.5"\n overlay: 3875

I used this approach for the 5 custom chime slots, but adding another set for the segment presets would extend the height of the configuration page even more. Another issue is that there is no way split up the configuration page with headings…it’s just one long list. Without headings it becomes visually quite difficult to understand, even if I add only 5 fields.

This approach is quite ugly, but the main issue I think is that it would be difficult to read & modify.

configuration

2. Add a new service: chime_tts.manage_presets

I could create a new Chime TTS service which users could use to both view and modify their segment presets. While this solution is straightforward, I don’t like the idea of having the configuration be split into two different locations.

3. Add a webpage to manage section presets

I could create a small web app inside Home Assistant, which could be accessible via the sidebar, to allow users to easily view and modify their segment presets. If I go down this road I would move the remaining configuration options as well to keep them all together…but it feels like overkill just to support the new feature.

would it be possible to move to (a) config.yaml?
lots of integrations a working on getting everything into the UI but if the setup is as limited, moving to the UI may just not be the best option yet.

Yes, it would probably make it easier, but at the same time it would break the current configuration values for users which would be a pain and also potentially break the integration for them.

I’m using Chime TTS with Raspiaudo Muse Luxe in ESP Home because I wanted a completely local solution. It’s great but unfortunately, Chime insists on sending the path to the created mp3 file using my Nabua Casa external URL, not my internal local ip. I’ve confirmed that in the Muse Luxe log file. How do I set it to use a local path ONLY

Hey @def1149.

I could add a toggle parameter to the chime_tts.say_url service to define whether the URL should use the local or remote path, but I believe you can already achieve this using templating. You would need to perform a find/replace to switch the remote path to the local IP address.

{{ remote_url | replace('remote_domain', 'local_ip') }}

Thanks but I’m not using chime_tts.say_url I’m using chime_tts.say

Why is it using my external url?

Still looking for an answer on why chime_tts.say uses my external Nabu Casa URL for the path to the mp3 file created and not my local internal path when sending the play to ESP Muse luxe
The following is from the Muse luxe log file.

[D][media_player:066]:   Media URL: https:/[redacted].ui.nabu.casa/media/local/sounds/temp/chime_tts/3ppbo8a7.mp3

Hi @def1149.

I just released a beta version which switches the paths used for local files from the external URL to the internal local one.
Can you please upgrade the the new versinon, v0.12.1-beta2, and let me know if the issue is resolved?

To install the new beta version:

  1. Open the Chime TTS repository in HACS
  2. Click on the button in the top right
  3. Select the ↻ Redownload option
  4. Enable the Show beta versions option (it may take a moment to update the list)
  5. Select version v0.12.1-beta2 from the updated version drop-down list
  6. Restart Home Assistant

OK … I’ll do that now

Thanks, but that didn’t fix the problem, I also cleared the cache and performed a hard boot and that still failed to change to use the local path. Maybe Nabu Casa will give you a developer account to help with debugging and testing

I don’t know if this will help. I’m using a Squeezelit-ESP32 and used the local path.
chime_path: /config/www/tony/xxxx.mp3

This is not a static mp3 file … it was created by Piper TTS so the actual file name is unknown until created

Thanks for the feedback.

I found and fixed the issue. Can you please download the new version, v0.12.1-beta3, restart Home Assistant and try again?

  1. Open the Chime TTS repository in HACS

  2. Click on the button in the top right

  3. Select the ↻ Redownload option

  4. Enable the Show beta versions option (it may take a moment to update the list)

  5. Select version v0.12.1-beta3 from the updated version drop-down list

  6. Restart Home Assistant

Still not working

Can you please enable debug logging and send me your logs?

To turn on debug logging:

  1. Go to the Chime TTS integration in Home Assistant: https:/{YOUR_ADDRESS}:8123/config/integrations/integration/chime_tts
  2. Click Enable debug logging
  3. View your logs:
    https://{YOUR_ADDRESS}:8123/config/logs?filter=chime_tts
  4. Click LOAD FULL LOGS
2024-01-22 14:55:56.587 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration chime_tts which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-01-22 16:01:36.802 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Called. Version v0.12.1-beta3 -----
2024-01-22 16:01:36.802 DEBUG (MainThread) [custom_components.chime_tts] Service call #0 was added to the queue.
2024-01-22 16:01:36.802 DEBUG (MainThread) [custom_components.chime_tts] Executing queued job #0
2024-01-22 16:01:36.806 DEBUG (MainThread) [custom_components.chime_tts.helpers] ----- General Parameters -----
2024-01-22 16:01:36.806 DEBUG (MainThread) [custom_components.chime_tts.helpers] * entity_ids = ['media_player.raspiaudio_muse_luxe_bbc618_raspiaudio_muse_luxe_bbc618']
2024-01-22 16:01:36.806 DEBUG (MainThread) [custom_components.chime_tts.helpers] * chime_path = bells
2024-01-22 16:01:36.807 DEBUG (MainThread) [custom_components.chime_tts.helpers] * end_chime_path =
2024-01-22 16:01:36.807 DEBUG (MainThread) [custom_components.chime_tts.helpers] * cache = False
2024-01-22 16:01:36.807 DEBUG (MainThread) [custom_components.chime_tts.helpers] * delay = 450.0
2024-01-22 16:01:36.807 DEBUG (MainThread) [custom_components.chime_tts.helpers] * final_delay = 0.0
2024-01-22 16:01:36.807 DEBUG (MainThread) [custom_components.chime_tts.helpers] * message = This is a post change test
2024-01-22 16:01:36.809 DEBUG (MainThread) [custom_components.chime_tts.helpers] * tts_platform = tts.piper
2024-01-22 16:01:36.810 DEBUG (MainThread) [custom_components.chime_tts.helpers] * tts_playback_speed = 100.0
2024-01-22 16:01:36.810 DEBUG (MainThread) [custom_components.chime_tts.helpers] * announce = False
2024-01-22 16:01:36.810 DEBUG (MainThread) [custom_components.chime_tts.helpers] * volume_level = 1.0
2024-01-22 16:01:36.810 DEBUG (MainThread) [custom_components.chime_tts.helpers] * join_players = False
2024-01-22 16:01:36.810 DEBUG (MainThread) [custom_components.chime_tts.helpers] * unjoin_players = False
2024-01-22 16:01:36.811 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path
2024-01-22 16:01:36.811 DEBUG (MainThread) [custom_components.chime_tts] Retrieving audio from path: "custom_components/chime_tts/mp3s/bells.mp3"
2024-01-22 16:01:37.122 DEBUG (MainThread) [custom_components.chime_tts] - Audio retrieved. Duration: 0.944s
2024-01-22 16:01:37.123 DEBUG (MainThread) [custom_components.chime_tts] async_request_tts_audio(tts_platform='tts.piper', message='This is a post change test', tts_playback_speed=100.0, cache=False, language=None, options={})
2024-01-22 16:01:37.123 DEBUG (MainThread) [custom_components.chime_tts] - Generating TTS audio...
2024-01-22 16:01:38.610 DEBUG (MainThread) [custom_components.chime_tts] - ...TTS audio completed in 1486.784 ms
2024-01-22 16:01:38.613 DEBUG (MainThread) [custom_components.chime_tts.helpers] Performing delay of 450.0ms
2024-01-22 16:01:38.619 DEBUG (MainThread) [custom_components.chime_tts] - Final audio created. Duration: 3.324s
2024-01-22 16:01:38.619 DEBUG (MainThread) [custom_components.chime_tts] - Saving mp3 file...
2024-01-22 16:01:38.860 DEBUG (MainThread) [custom_components.chime_tts.helpers] - File saved successfully
2024-01-22 16:01:38.860 DEBUG (MainThread) [custom_components.chime_tts.helpers] - File saved to path: /media/sounds/temp/chime_tts/f86bsgul.mp3
2024-01-22 16:01:38.860 DEBUG (MainThread) [custom_components.chime_tts] - Filepath = '/media/sounds/temp/chime_tts/f86bsgul.mp3'
2024-01-22 16:01:38.861 DEBUG (MainThread) [custom_components.chime_tts] - File saved successfully
2024-01-22 16:01:38.861 DEBUG (MainThread) [custom_components.chime_tts] - audio_dict = {'audio_path': '/media/sounds/temp/chime_tts/f86bsgul.mp3', 'audio_duration': 3.324}
2024-01-22 16:01:38.861 DEBUG (MainThread) [custom_components.chime_tts] - Setting 'media_player.raspiaudio_muse_luxe_bbc618_raspiaudio_muse_luxe_bbc618' volume level to 1.0
2024-01-22 16:01:38.861 DEBUG (MainThread) [custom_components.chime_tts] - async_set_volume_level("media_player.raspiaudio_muse_luxe_bbc618_raspiaudio_muse_luxe_bbc618", 1.0)
2024-01-22 16:01:38.861 DEBUG (MainThread) [custom_components.chime_tts] - Skipped setting volume
2024-01-22 16:01:38.861 DEBUG (MainThread) [custom_components.chime_tts] Calling media_player.play_media service with data:
2024-01-22 16:01:38.862 DEBUG (MainThread) [custom_components.chime_tts] - media_content_type: music
2024-01-22 16:01:38.862 DEBUG (MainThread) [custom_components.chime_tts] - media_content_id: media-source://media_source/local/sounds/temp/chime_tts/f86bsgul.mp3
2024-01-22 16:01:38.862 DEBUG (MainThread) [custom_components.chime_tts] - entity_id: ['media_player.raspiaudio_muse_luxe_bbc618_raspiaudio_muse_luxe_bbc618']
2024-01-22 16:01:38.877 DEBUG (MainThread) [custom_components.chime_tts] ...media_player.play_media completed.
2024-01-22 16:01:38.877 DEBUG (MainThread) [custom_components.chime_tts] Waiting 3.324s for audio playback to complete...
2024-01-22 16:01:42.204 DEBUG (MainThread) [custom_components.chime_tts] Returning media_player.raspiaudio_muse_luxe_bbc618_raspiaudio_muse_luxe_bbc618's volume level to 1.0
2024-01-22 16:01:42.204 DEBUG (MainThread) [custom_components.chime_tts] - async_set_volume_level("media_player.raspiaudio_muse_luxe_bbc618_raspiaudio_muse_luxe_bbc618", 1.0)
2024-01-22 16:01:42.204 DEBUG (MainThread) [custom_components.chime_tts] - Skipped setting volume
2024-01-22 16:01:42.210 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Completed in 5407.37 ms -----
2024-01-22 16:01:42.211 DEBUG (MainThread) [custom_components.chime_tts] Removing current queued service call.
2024-01-22 16:01:42.211 DEBUG (MainThread) [custom_components.chime_tts] Queue emptied. Reinitializing values.