Using Siri to control Spotify through python

I have always wanted to control Spotify through Siri. It has always seemed like a waste for Apple to include fantastic voice recognition software and then completely refuse to integrate it into 3rd party apps.
On reddit, /u/theraspberryguy posted a great project that allowed anyone to hook into Siri’s voice commands. Here is his github project and website. The project works the following way:
- You use Siri to create a note, for example by saying “Note Spotify artist James Brown”.
- Siri creates the Note in your Gmail’s note account.
- The github project sees that there is a new Gmail note (“Spotify artist James Brown”) and executes the proper module
- My spotify module hooks into Spotify to change the current playback artist to “James Brown”
Configuring Siri-Control
All configuration for the Siri-Control can be found on the projects website.
Configuring Spotipy with Playback Controls
The ability for Spotify’s API to control playback and track selection is new and still in Beta. It is known as the Web Connect API and will only work if you have Spotify Premium.
Spotipy is a “lightweight python library for the Spotify API”. It is great to work with, however it currently doesn’t support the Web Connect API. In order to get it working with the new API, we should download a Pull Request that implements the new features. We can download the repo from the PR with the following command
git clone https://github.com/happyleavesaoc/spotipy -b connect-apiNext you will want to configure Spotipy normally. I found this slightly confusing so here is are step-by-step instructions.
First install it using the following command
python setup.py installNext you should add your credentials through shell variables. Run the following commands before executing spotipy:
export SPOTIPY_CLIENT_ID='your-spotify-client-id'
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
export SPOTIPY_REDIRECT_URI='http://localhost:8888/connect/'The first two can be found by creating a spotify application. The redirect URL is the website that your application is hosted at. Because we are not hosting an application, we point it back at localhost. We don’t need anything to be hosted there, we are only looking for the information Spotify sends back.
When you create an application, make sure that you add the same redirect URL to spotify. It should look like this:

Getting the Spotify Module for Siri-Control
My short Spotify Module is available here. It is 43 lines long and simple to understand. It can search for Artists and Albums and play them on Spotify.
Download the module in SiriControl-System/modules/ . You will be able to control spotify through Siri as long as you keep a computer running that script! You will then be able to run the whole thing with the command:
python SiriControl-System/siricontrol.py