Recently I need to clean up my living room and move the speakers back to my home office. But the office layout is different now, so I had to place the speakers behind my working position. I don't have long enough cable to plug the audio source on my work desk. I've planned to buy a multi-channel snake cable so I can plug my phone or computer from the desk. But wait, this is overkill, and not convenient.
I remembered that my Raspberry Pi is sitting perfectly right there on the rack next to the sound card that's supplying audio to the speakers. My Pi obviously can supply audio to the sound card, but the question is, can I control the Pi to play music remotely?
I used the speakers to listen to music most of the time, and I stream music from Spotify. Unfortunately there's no official Spotify app for Pi. I had to improvise. After searching the forums I found the perfect method I can play Spotify on the Pi in a headless environment using Raspotify.
Raspotify is a package that runs Librespot, an open source Spotify client library. It's a one liner installation:
sudo apt-get -y install curl && curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
That's it! This library enables the Pi to be a Spotify Connect enabled device. Spotify Connect is a feature where you can play the music in different devices that you select, this including smart home devices and internet-connected speaker.
Now when I want to play the music on my speakers I just open Spotify select raspotify as my player.