DEV Community

Azimjon Pulatov
Azimjon Pulatov

Posted on

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 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

Top comments (0)