Is there a way to have a wild card in a slot

For example:

if i want to tell rhasspy to play a song, and have my code play that song if found, how do provide the intent with the value i have spoken which could be any one of hundreds of names.
right now i am using [‘rawInput’] but it seems there is probably a better approach.

[PlaySong]
ps_song=(could a wild card go here) {song}
play song <ps_song>

1 Like

I had the same problem. I solved it by creating a NODE RED flow that fetches all albums saved in my Spotify library (using the Spotify developer API) and all songs and artists from these. Then i created three slot programs which simply use curl to fetch this information from my NODE RED flow. e.g.

# in <profile_folder>/slot_programs/spotify_artists
#!/bin/bash
curl http://<ip-address-of-node-red>/endpoint/spotify-artists

The flow returns pure text with all the artists in my library, one per line. I also sanitized the output a bit (as Rhasspy doesn’t like punctuation and special characters in its slots). Same thing for two other slot programs which fetch albums and song names. Now I can use these in my rules like this:

[PlayMusic]
album = $spotify_albums{album}
artist = $spotify_artists{artist}
track = $spotify_tracks{track}
where = [(at|in) the $zones{zone}]
play something by <artist> <where>
play the album <album> [by <artist>] <where>
play the song <track> [by <artist>] <where>

The intent is then sent to another NODE RED flow which again uses the Spotify API to find a match, takes the URL of the first match and then uses Home Assistant’s media player service to play that URL on one of my Sonos speakers.

Pros:

  • It is reasonably accurate because it uses data from your library so it is more likely to actually find something you are interested in instead of having a totally free form thing which may or may not find what you are looking for.
  • It self-updates whenever you add songs to your library, you just need to re-train.
  • If multiple people live in your home with their own Spotify accounts you can fetch their libraries, too without needing to change the rest of the setup.

Cons:

  • You really need to sanitize the output from Spotify. Kill all the punctuation and special characters.
  • You really need to sanitize the output from Spotify. You want to say “play the song Mother by Pink Floyd” instead of “play the song Mother - 2011 remastered edition by Pink Floyd”. This means you need to strip out all the remastering fluff.
  • You really need to sanitize the output from Spotify. You want to say “play the album Privateering by Mark Knopfler” instead of “play the album Privatering Deluxe Version by Mark Knopfler”. So album versions are also quite of a pain.
  • And there are a lot of other small things that need sanitization and that I fix on a case by case basis. This really is the biggest drawback of this method.
  • Depending on the size of your library it can increase training time quite a bit.
1 Like