DEV Community

Azimjon Pulatov
Azimjon Pulatov

Posted on

14 4

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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay