Emulate the tactile experience of a vinyl collection through your Sonos system, but with a back end run by Spotify

hankhank10, updated 🕥 2022-09-18 13:18:05

vinylemulator

Emulate the tactile experience of a vinyl collection through your Sonos system, but with a back end run by Spotify.

There is a step-by-step tutorial on how to set this up from first principles on a Raspberry Pi here: https://www.hackster.io/mark-hank/sonos-spotify-vinyl-emulator-ssve-3be63d

Update: confirmed works with Sonos S2 released 8 June 2020

Update: this code relies on NFCpy which is incompatible with some newer card readers. You may wish to use Node Sonos NFC rather than this library. This is a Node implementation of this idea - the NFC cards should be compatible between both implementations.

Description

Start playing a Spotify album or playlist through Sonos when you place a physical object on an NFC reader connected to a Raspberry Pi.

You can attach these tiny NFC tags to any physical object you want: I like polaroid-style prints of album covers and tape cassettes for playlists/mixtapes, but you do you; send me a photo if you're baller enough to print album art on 12-inch square aluminium plates and tag it to that.

Background

Originally forked from musicbox project which was itself a fork from songblocks project. I have rewritten and simplified this a lot, however, so this version looks very different to those two.

All the actual back end work of this is done by the node-sonos-http-api which will need to be installed and set up in order to work.

This is not the first project to link NFC to Sonos / Spotify, but I couldn't find one that did both in the way I wanted. Unlike other projects of this type - which take a NFC tag id and cross reference that against a database on the Raspberry Pi to find the music URI - this project actually stores the album details directly on the NFC tag. This has a few advantages:

First, you can have a very large collection which will continue to exist independent of digital storage on the Raspberry Pi. Even if you manage to wipe the database on your Pi, your collection will live forever (just like real vinyl);

Second, these NFC tags aren't tied to the particular Raspberry Pi. This means that the tags are portable to other Raspberry Pis running the same scripts. So take your favourite jazz album from your city pad up to the country house to listen to in the study when it's Laphroig time, or take a rare deep cut you've stumbled across to a friend's house for a listening party. Other use cases are available for those who aren't millionaires.

It also means that other applications can read the tags - I am working on an implementation for Android phones which don't rely on Pi for the NFC, for instance.

It's all coded in Python. Kind of.

Usage

This currently accesses three any of three different services depending on the content of the NFC tag presented. The relevant service is determined by the start of the text passed by the NFC tag.

| Service name | Behaviour | | ---------------- | --------------- | | spotify: | Plays a spotify album, track or playlist URI | | tunein: | Plays a radio station identified by a tunein ID number | | bbcsounds: | Plays a BBC radio station identified by stream name as detailed in node-sonos-http-api readme | | apple: | Plays a Apple Music album, track or playlist URI | | amazonmusic: | Plays a Amazon Music album, track or playlist URI | | room: | Changes the room in which the script plays| | command: | Executes a command in the current room; can accept any command as defined in node-sonos-http-api | | favorite: | Plays a Sonos favorite identified by its name |

Examples of what can be passed:

```sh

  spotify:track:4LI1ykYGFCcXPWkrpcU7hn
  spotify:album:4hW2wvP51Myt7UIVTgSp4f
  spotify:user:spotify:playlist:32O0SSXDNWDrMievPkV0Im

  tunein/play/44491

  favourite/BBC_Radio_2

  bbcsounds:bbc_radio_two

  command:playpause
  command:mute
  command:next
  command:volume/50
  command:volume/+10
  command:shuffle/on

```

Setup instructions

I made a full tutorial, starting from absolute first principles, here: https://www.hackster.io/mark-hank/sonos-spotify-vinyl-emulator-ssve-3be63d

Important note

Since developing this code in early 2020 it's become apparent that a number of the newer ACR122U NFC readers (which is what I recommended for this project) are not compatible with NFCpy, which is the library that my Python code uses.

Even worse, there seems to be no way to know whether the ACR122U reader you are going to get will work or not... which is annoying.

Luckily ryanolf has created a new library which is compatible with the newer readers and is available here: https://github.com/ryanolf/node-sonos-nfc

Anonymous stats

This is set up to send anonymous usage stats for the purposes of debugging. All that is stored is an anonymised uuid generated by your Raspberry Pi (so not linked to you at all), a log when the app starts, the NFC payload received and how the app interprets this. You can turn this off by changing the relevant setting in usersettings.py to anything except "yes"

Issues

Support for RC522

opened on 2022-03-30 20:43:34 by deve2ev

I have installed an RC522as an RFID reader/writer, but I don't know what device path to use. It doesn't show up using lsusb. What should I do?

Autostop possible?

opened on 2021-12-18 20:48:44 by G0bi83

Hi, awesome project! I made it with a raspberry pi Zero 2 and it works like a charm. I have done it for my son and it would be great if something like an „album“ starts when the nfc tag is recognized and stops automatically if the tag is removed. Like a Tonie Box. Would this be possible?

thanks

500 error from terminal, but 200 from browser

opened on 2021-10-13 01:18:31 by mbecker4

I'm hitting the endpoint on my raspberry pi with python trying to play a song in the living room with the following:

r = requests.get('http://localhost:5005/Living%20Room/applemusic/now/album:370090822')

When running in terminal I get a 500 {"status":"error"}

However when I copy the exact url and paste it into a browser it works and I get {"status":"success"}

I am still relatively new to python so I'm hoping I didn't overlook something obvious. But any clarification on why this would be happening would be much appreciated.

Everything works with Sony NFC reader, but albums all play shuffled?

opened on 2021-03-22 16:35:59 by caffeinePlease

Followed the guide as best I could get everything working (I had an incompatible Yosoo reader that was fixed by using a Sony) and tapping the reader with a tag gets music to play, but each time I tap, it plays a different song from the album.

Spotify doesn't appear to be in "shuffle" mode and same thing for Sonos, as far as I can tell. What things should I check to ensure proper playback?

Can't seem to get acr122u to beep when a tag is read?

opened on 2021-03-06 22:30:23 by parth0295

Is there a way to turn on the beep on the ACR122U? It beeps when I am running nfctools but not when running the sonos vinyl emulator like it does in the demo video.

Thanks!

Spotify “end session” command through Sonos api?

opened on 2020-10-12 17:06:20 by Nayhtohn

I’m wondering if you can help with an issue I’m running into:

When I have a queue setup from the Sonos app the emulator works fine, but when I start a song from the Spotify app it doesn’t work and I have to go into the Sonos app and press “end session” before the emulator can work.

I can’t see on the Sonos api a command for end session, and clearqueue doesn’t seem to work - do you know if such a command exists? Or how I can watch the api command line when I press a button in the app to see what it tells the system to do?

Thanks, Ben

Releases

Version 0.5 - compatible with S2 2020-06-08 16:54:13

Confirmed works with Sonos S2 released today

sonos spotify node-spotify-api raspberry pi python nfc