How I Built Spotify Alternative for Google Home

It was Sunday night. Hackathon results were about to be announced and when I heard my team’s name, I jumped out of my chair, I was thrilled. To add more excitement, I asked my Google Home to play “We Are The Champions” and to my surprise, it played tot…


This content originally appeared on DEV Community and was authored by Azimjon Pulatov

It was Sunday night. Hackathon results were about to be announced and when I heard my team's name, I jumped out of my chair, I was thrilled. To add more excitement, I asked my Google Home to play "We Are The Champions" and to my surprise, it played totally different song. I could be disappointed but instead, I was inspired to know what I was building next.

Why did it play a different song? Because choosing songs is only available to Spotify Premium subscribers. Instead of subscribing, I decided to build an alternative myself.

From the day I got my Google Home, I was wondering how to program it to do things I want. The first and easiest option was IFTTT. After connecting my Google Account, I was able to make simple applets that allowed to make Google Assistant say things back when certain questions were asked and bind it to actions like making a web request.

IFTTT Simple Phrase Applet

IFTTT wasn't quite what I was looking for, because it couldn't perform tasks like playing audio or programmatically generate a response. Then I discovered Google Actions. When I saw its capabilities, I realized - this is the way.

The first thing I needed to set up for the application was a webhook. So whenever the application gets invoked, Google Action makes a request to the webhook. One way to provide a publicly available URL for the webhook would be to deploy the application somewhere. Instead, for the development, I used JPRQ, a Ngrok Alternative for exposing a local webserver. You can read about how I built it.

Setting Up WebHook in Google Actions

After setting up the webhook, my local server was receiving anything I say to Google Assistant after the application was invoked. I could easily send a media response - a playable URL, and the assistant would play it. Great!

The best tutorial I could find on Google Actions is Behind the Actions, it helped me to understand basic building blocks like Scenes, Types, and Intents.

The next part is searching for songs. I first looked into available APIs provided by Deezer, Sound Cloud, and Apple Music. But none of them provided the full song, only the partial content. Then I decided to write a simple crawler to search songs from z1.fm. I thought about copyright issues, so I decided to keep MusicSpider to myself and not publish it for others.

Source code for MusicSpider is available on Github, both the web application built using Flask and the crawler for searching for songs.

To share my learnings, I gave a talk about "Programmable Google Assistant" where I also shared some of my other applications I built for Google Assistant.

Happy building,

Cheers


This content originally appeared on DEV Community and was authored by Azimjon Pulatov


Print Share Comment Cite Upload Translate
APA
Azimjon Pulatov | Sciencx (2022-09-26T19:57:29+00:00) » How I Built Spotify Alternative for Google Home. Retrieved from https://www.scien.cx/2021/05/02/how-i-built-spotify-alternative-for-google-home/.
MLA
" » How I Built Spotify Alternative for Google Home." Azimjon Pulatov | Sciencx - Sunday May 2, 2021, https://www.scien.cx/2021/05/02/how-i-built-spotify-alternative-for-google-home/
HARVARD
Azimjon Pulatov | Sciencx Sunday May 2, 2021 » How I Built Spotify Alternative for Google Home., viewed 2022-09-26T19:57:29+00:00,<https://www.scien.cx/2021/05/02/how-i-built-spotify-alternative-for-google-home/>
VANCOUVER
Azimjon Pulatov | Sciencx - » How I Built Spotify Alternative for Google Home. [Internet]. [Accessed 2022-09-26T19:57:29+00:00]. Available from: https://www.scien.cx/2021/05/02/how-i-built-spotify-alternative-for-google-home/
CHICAGO
" » How I Built Spotify Alternative for Google Home." Azimjon Pulatov | Sciencx - Accessed 2022-09-26T19:57:29+00:00. https://www.scien.cx/2021/05/02/how-i-built-spotify-alternative-for-google-home/
IEEE
" » How I Built Spotify Alternative for Google Home." Azimjon Pulatov | Sciencx [Online]. Available: https://www.scien.cx/2021/05/02/how-i-built-spotify-alternative-for-google-home/. [Accessed: 2022-09-26T19:57:29+00:00]
rf:citation
» How I Built Spotify Alternative for Google Home | Azimjon Pulatov | Sciencx | https://www.scien.cx/2021/05/02/how-i-built-spotify-alternative-for-google-home/ | 2022-09-26T19:57:29+00:00
https://github.com/addpipe/simple-recorderjs-demo