Text-to-Speech problem with Chromecast Audio

I’ve noticed the same thing. As a workaround for my reminders I set the volume and then delay 10 seconds before playing. 10s is probably overkill but I haven’t had time to tweak it yet.

   action:
  - service: media_player.volume_set
    data:
      entity_id: media_player.entrance
      volume_level: '0.30'
  - delay: 00:00:10
  - service: media_player.play_media
    data_template: etc...
1 Like

I use this automation to keep the connection so it does not go into standby/off mode

- alias: Keep Google Home Alive
  trigger:
    platform: time
    minutes: '/2'
    seconds: 00
  condition:
    - condition: template
      value_template: '{{ states.media_player.kitchen_google_mini.state != "playing"}}'
    - condition: template
      value_template: '{{ states.media_player.living_room_google_mini.state != "playing"}}'
    - condition: template
      value_template: '{{ states.media_player.google_home_minis.state != "playing"}}'
  action:
    service: media_player.play_media
    entity_id: media_player.google_home_minis
    data:
      media_content_id: http://192.168.0.24/audio1sec.mp3
      media_content_type: music
1 Like

Thanks tom_I, that worked perfectly. In fact, it worked equally great when I removed the delay completely :slight_smile:

it’ll work great as long as your CC is idle. After being idle for about 5 min it’ll go off.
When you play something then, first you’ll hear the annoying connection noise and you may lose the beginning of your announcement hence the script above…

1 Like

Okay, I will give this a shot tomorrow. I noticed that the Chromecast played a connection sound some of the times which would be nice to get rid of.

But it seems that your automation only triggers every 2 minutes. The issue with the beginning of the announcement getting dropped happens far more often that that.

Maybe the two solutions work good together.

Thanks for your help.

that’s why I have this automation, I NEVER miss the beginning of an announcement and I only hear the connection sound when I restart HA (which takes a few minutes.
I have to say credit’s where credit’s due though, the original idea/automation came from @hoffsta, check his post here

1 Like

Triggering lolouk44’s automation every 2 minutes should be often enough the keep the Chromecasts always connected/awake. It prevents them turning off as this power saving mode happens after about 5 minutes of being idle.

I’m assuming the audio1sec.mp3 file is one second of silence? EDIT: it is. I just read the link to hoffsta’s post.

It’s an interesting solution. I will probably change to it so I dont need the delay for instant TTS alerts. I only use TTS for reminders at the moment and they are not time critical but I have plans to use this more often.

In fact at some stage I am going to overhaul my entire alerting method to have one alert script that decides where (three apple devices, three Chromecasts, TVs, Kodi boxes, ect…) to send text messages, TTS, or play sounds and have each automation just pass the message and a priority to this script. Got a lot of other basic things to fix/develop first though.

I ran into a problem using the method with media_player.volume_set.
When trying to set the volume to for example 0.5, when the volume was already 0.5, the issue with the sound beeing cut at the beginning was still present. And setting different sound levels, 0.51 and 0.52 for different TTS announcements feels like a bad idea.

I also tried to mute and unmute the sound before playing the TTS message, but the problem was present there too.

One solution that seem to work though is this:

tts_temp_microsoft:
  alias: Temperatur (Microsoft)
  sequence:
    - service: media_player.play_media
      entity_id: media_player.sovrum
      data:
        media_content_id: https://myserver:8123/local/audio/silence_1sec.mp3
        media_content_type: music
    - delay:
        seconds: 0.1
    - service: tts.microsoft_say
      entity_id: media_player.sovrum
      data_template:
        message: "Det är {{states('sensor.ute_temperature')}} grader ute."

In short:

  1. Play 1 second of silence.
  2. Delay for 0.1 seconds (without this delay, the problem persist)
  3. Then play the TTS announcement.

In combination with the automation from @lolouk44 the Chromecast Audio doesn’t go to sleep and the TTS are played without cut-outs (as of now). I will continue with my testing and let you now of any further failures.

2 Likes

Today I have found yet another way to solve the issue at hand. And it works without both the automation playing a 1 seconds silence every two minutes (which by the way stops the music when playing from a music app on the iPhone) and without changing the volume before every TTS announcment.

For some reason I cannot explain it works perfect :slight_smile: (at least in my setup)

tts_temp_microsoft:
  alias: Temperatur (Microsoft TTS)
  sequence:
    - service: media_player.play_media
      entity_id: media_player.sovrum
      data:
        media_content_id: https://server:8123/local/audio/silence_1sec.mp3
        media_content_type: music
    - wait_template: "{{ states('media_player.sovrum') != 'off' }}"
    - delay:
        seconds: 0.1
    - service: tts.microsoft_say
      entity_id: media_player.sovrum
      data_template:
        message: "Det är {{states('sensor.ute_temperature')}} grader ute."

The secret seem to be to wait until the Chromecast Audio isn’t off followed by a short delay.

If someone could try it out and hopefully have the same luck as I did it would be great.

2 Likes

if you look at my automation it’ll check that the GH is not already playing before it plays the 1 sec audio :wink:
(actually I check that each individual GH and the group with both my GH devices isn’t in playing state )
Your method with work too though you’d have an ever slight delay before you hear the announcement, and most likely you’ll also hear the connection chime which I hate…

if you look at my automation it’ll check that the GH is not already playing before it plays the 1 sec audio

Yes, I noticed that :wink: But that only work if I stream music from Home Assistant to the Chromecast Audio. When I stream music from Spotify and apps alike to the Chromecast, Home Assistant is unaware of the status of the Chromecast Audio. It is seen as off.

Your method with work too though you’d have an ever slight delay before you hear the announcement, and most likely you’ll also hear the connection chime which I hate…

That was the weird thing. When using the wait_template and the delay I don’t hear the “connection chime”, it just starts playing the TTS announcement, perfectly complete. Even if the Chromecast is in the idle or off state.

Maybe you could give it a shot and see how your device behave? There might be some difference in how the Google Home and the Chromecast Audio operate. I would be really interested anyway because I intend to buy a Google Home Mini soon :yum:

Interesting. Google Home acts as a ChromeCast audio so from from HA’s point of view it makes not difference. I actually use ChromeCasts to play music and my GH’s for announcements (and regular interactions)
I’ll see if I get some time to try your method…

1 Like

I tried the wait template. The chromecast audio did go from off to playing without the connection tones.

Also I’m going to try the turn_on service instead of the 1sec silent mp3. e.g.

  action:
  - service: media_player.turn_on
    data:
      entity_id: media_player.entrance
  - wait_template: "{{ states('media_player.entrance') != 'off' }}"
  - service: media_player.volume_set
    data:
      entity_id: media_player.entrance
      volume_level: '0.30'
  - service: media_player.play_media
    data_template:
      entity_id: media_player.entrance
      media_content_id: https:/xxxxx.duckdns.org/local/sounds/Reminder.mp3
      media_content_type: 'audio/mp3'

It looks right and HA config check passes but I’m not there to hear it at the moment so don’t know for sure.

EDIT: this doesn’t work.

1 Like

So I got around to implementing @lolouk44’s connection keep-alive automation.

It does keep my chromecast audio from turning off but I’m still missing the first part of every announcement or TTS message.

I even tried playing the 1 second silence clip before playing the file I wanted. Still clipping the first part of the message.

Can you share your code?

Sure, this is the original, without the extra silence.mp3 played first. I even tried playing the doorbell mp3 twice. No change.

#################################################################
## Audio Player Keep Alive
#################################################################

- id: keep_audio_player_alive
  alias: Keep Audio Player Alive
  trigger:
    platform: time
    minutes: '/2'
    seconds: 00
  condition:
    - condition: template
      value_template: '{{ states.media_player.entrance.state != "playing"}}'
  action:
    service: media_player.play_media
    data:
      entity_id: media_player.entrance
      media_content_id: https://mydomain.duckdns.org/local/sounds/audio1sec.mp3
      media_content_type: music

#################################################################
## Doorbell Automations
#################################################################

- id: doorbell_alert
  alias: 'Doorbell Alert'
  trigger:
    entity_id: binary_sensor.doorbell
    platform: state
    to: 'on'
  action:
  - service: camera.snapshot
    data:
      entity_id: camera.front
      filename: '/config/www/doorbell.jpg'
  - service: notify.all_ios_devices
    data:
      message: Someone has pressed the doorbell.
      data:
        push:
          sound: "Doorbell.wav"
        attachment:
          url: https://mydonmain.duckdns.org/local/doorbell.jpg
  - service: media_player.volume_set
    data:
      entity_id: media_player.entrance
      volume_level: '0.30'
  - service: media_player.play_media
    data:
      entity_id: media_player.entrance
      media_content_id: https://mydomain.duckdns.org/local/sounds/Doorbell2.mp3
      media_content_type: 'audio/mp3'
  - service: automation.turn_off
    entity_id: automation.doorbell_alert
  - delay: 00:00:05
  - service: automation.turn_on
    entity_id: automation.doorbell_alert

I tried with this as well but it made no difference.

      media_content_type: music

not sure why you’re missing the beginning.
Quick question, why do you have this:

  - service: automation.turn_off
    entity_id: automation.doorbell_alert
  - delay: 00:00:05
  - service: automation.turn_on
    entity_id: automation.doorbell_alert

Also I personally find that audio/mp4 is more reliable than other formats. Can you can try for both the doorbell play and the keep alive?
Also you mentioned TTS, but it looks like you’re playing some MP3 file. Where is the TTS?
What happens when you manually play the mp3 on the media_player via the Services tab?
image

So I dont get multiple notifications if some impatient person repeatedly presses the doorbell.

I’ll give it a go.

TTS testing was directly from the media player panel. It misses the first part of the message.

I’m not entirely sure how to specify the service data there. This doesn’t play:

{
  "entity_id": "media_player.entrance",
  "media_content_id": " https://mydomain.duckdns.org/local/sounds/Doorbell2.mp3",
  "media_content_type": "audio/mp3"
}

better add this condition to your automation:

    - condition: template
      value_template: '{{ (as_timestamp(now()) - as_timestamp(state_attr("automation.doorbell_alert", "last_triggered") | default(0)) | int > 5)}}'

Not that it should, but wondering if setting the volume makes the CC “busy”.
Have you tried to add a delay of like 1 sec between volume set and play? I don’t have that issue personally, but worth a try

For me it’s the same, not entirely sure why. I ended up loading the sound files on my webserver (apache) and linking to it using the server’s IP address rather than going online for it.

I like that! Thanks.

Also did you mean mA4 format?

I don’t seem to be able to export mp4 from audacity.