Sonos tts wait template

I’ve been trying to figure out how to dynamically adjust the tts delay for automations. Some of my tts scripts are a couple of words while others are a couple sentences. I currently just have a delay set. on the shorter automations it can end up leaving no audio for a minute or so. I haven’t been able to find a working template to adjust this based on what is being played. Does anyone have something like this they would be willing to share?

You could probably use wait_template, but there’s currently an open issue with it.

@Darbos

I’ve used a script which I found over here. https://community.home-assistant.io/t/sonos-tts-script/8896
Makes a snapshot of what is playing, waits for as long as the content of the TTS message, and returns playing.