Voice activated YouTube Music search #1589
gmurnane
started this conversation in
Show and tell
Replies: 1 comment
-
Also have a look at the new beta 5 of the HA integration, I included a new search service that returns data so that saves you maybe some of the duplicate code. Also the "play media" service now accepts search phrases as the content_id such as "Queen - Innuendo" or "Innuendo by Queen". |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted to be able to request songs verbally, without any prior interaction with those songs (not in the library, not favorited, not in a playlist), and get results pulled from YT Music. The approach I used is probably extensible to albums, and "Play songs by this artist" pretty easily, but so far the fully open source voice matching is pretty unreliable for exactly matching an artist's name, so I started with single songs. Luckily, YT Music does a pretty good job of guessing what was meant with whatever it's handed, and fuzzy matching between title and artist has been good enough for me.
I now have something like this working:
"Hey Jarvis ... play Magic Forest by Amberian Dawn" (Then Magic Forest by Amberian Dawn plays)
I am aware that Music Assistant already has python, with ytmusicapi, and authentication set up, and if I were a better developer, this might be best handled as an integrated feature.
Prerequisites:
I'm running the YT music search on an always-on Linux server, on my local network. This is required only because I don't know enough about running python as an addon for HA, so there's likely a way to remove the need for that Linux system entirely (and maybe improve the speed of this operation), but I don't expect to do it.
You need a configured voice assistant/wake word for HA. I followed the Year of the Voice $13 voice assistant tutorial. You also must have music assistant working, and connected to/able to play from YT Music.
Directions:
On the linux system, set up a new python venv, and install some pip packages:
Get a long-lived access token from your home assistant, and configure your home assistant URL, authorization token, and music assistant player_id in this script, and save it as yt_music_search_server.py:
Then launch that python server. It's probably more reliable to set it to launch at system start with a systemd unit file or something, but ideally this would eventually wind up on the HA device.
Now in home assistant, add this to /config/configuration.yaml:
Create the file /config/shell/play_song.sh, modifying the IP to match your linux server. This is broken out into a separate script because YAML didn't like my attempts to quote JSON with template values.
Finally, create /config/custom_sentences/en/play_music.yaml:
After HA is reloaded, the new sentence/intent should be working. I found it helpful to type to the Assist engine first to verify, then try the voice commands once that was working.
Beta Was this translation helpful? Give feedback.
All reactions