I know the original post is from 2017, but people are still commenting, and so I figure I’ll join in and do a little but of show and tell.
When I play something on Plex in the master bedroom, the nightstand speaker announces what’s playing.
In that TTS call I had 40+ phrases that I tried to have the random
command handle, like this:
{{[
'phrase 1',
'phrase 2',
'phrase 3,
'phrase 4',
...
'phrase 40-something'
]|random }}
It struggled a bit to give me truly random results. For over a week it would just repeat the same few phrases.
So I asked ChatGPT for some advice.
Hi everybody from 2017! We made it to 2023. We have ChatGPT now, but not flying cars
ChatGPT said I had too many phrases in the command, and suggested that I break them apart into groups.
So I created a temp variable, assigned a random number to it, grouped the phrases into buckets, then used basic if else
logic to match the value of the temp variable. Each bucket contained a list of 5 phrases that were then chosen randomly.
It’s worth noting that I’m using macros
for my TTS scripts. I find it’s easier to keep them all contained in the same place, and the developer tools plays nice with testing them. I followed SlackerLabs lead on using Macros: https://www.youtube.com/watch?v=XiLD9kgfXNI
Anyways, here’s my code:
{% set rand = range(1,9)|random %}
{% if rand == 1 %}
{{[
'Ohh, yay, its',
'Yaaas queen, its',
'Yoooo, check it, its',
'Hurray, lets watch',
'Such wow, so amaze, its'
] |random }}
{% elif rand == 2 %}
{{[
'Sweet, its',
'Oh my goodness, its',
'Golly gee its',
'Jeepers, its',
'Geewillikers, its'
] |random }}
{% elif rand == 3 %}
{{[
'Gee whiz, its',
'Hot dog, its',
'Holy cow, its',
'Groovy, its',
'Hot diggidy, its'
] |random }}
{% elif rand == 4 %}
{{[
'Awesome sauce, its',
'Whoa, dude, its',
'Right on, its',
'Oh my gosh, its',
'Oh m gee, its'
]|random }}
{% elif rand == 5 %}
{{[
'Ermahgard, its',
'Wowzers, its',
'Oh youre going to love this, its',
'Yippee kai yay, its',
'Okay, see, now Im excited, its'
]|random }}
{% elif rand == 6 %}
{{[
'Holy moly, its',
'Oh my word, its',
'Oh my goodness gracious, its',
'Whoa there, its',
'Whoa nelly, its'
]|random }}
{% elif rand == 7 %}
{{[
'Holy mackerel, its',
'Oh my stars, its',
'Holy smokes, its',
'Oh goodness gracious me, its',
'Woop woop, turn up, its'
]|random }}
{% elif rand == 8 %}
{{[
'Boss move, brah. Its',
'Got damn fam, nice choice. Its',
'Like, I like, literally like cant, its',
'Wait, wait. What? its',
'Oh man, its'
]|random }}
{% elif rand == 9 %}
{{[
'Listen up, its',
'Yo yo yo, its',
'Mamma mia, its'
]|random }}
{% else %}
{% endif %}
{# Name of Show #}
{{((state_attr('media_player.plex_master_bedroom', 'media_series_title'))) }}
season
{{((state_attr('media_player.plex_master_bedroom', 'media_season'))) }}
episode
{{((state_attr('media_player.plex_master_bedroom', 'media_episode'))) }}.
This one is called
{{((state_attr('media_player.plex_master_bedroom', 'media_title'))) }}.
That code runs pretty quickly and outputs something like:
Ermahgard, its Game of Thrones Season 1 episode one. This one is called Winter is Coming.
Wife approves.