Tormods blog

Feed on Comments 07 February 2012

Tormod Ravnanger Landet on 19 Jun 2009 10:18 pm

Streaming audio from Spotify on Linux to Squeezebox

I have tried the WaveInput route for SqueezeCenter, but due to a non-cooperative sound card and various problems with permissions related to SqueezeCenter running as a limited user I decided to go another route and stream sound from my Linux laptop via Icecast. If you want try using WaveInput and have the same problems with recording from the sound card as I have (it plain doesn’t work with arecord and friends) there is a recipe here that might work for you.

PulseAudio

I need to use PulseAudio to get recording of sound played through the sound card to work as my Intel sound card refuses to allow me to record the sound directly. Luckily PulseAudio finally works OK for me now. I configured Wine with padsp winecfg and chose the OSS output driver for sound (ALSA works poorly at the moment). Now, run Spotify as padsp wine spotify.exe. Spotify should pop up in your PulseAudio Volume Control (pavucontrol) in the Playback tab.

You need to define a PulseAudio sink that is different from the normal (output to PC speakers). I chose to call this sink spotify. Create the sink with the following command.

pactl load-module module-null-sink sink_name=spotify

The sink should pop up in the volume control under the Output Devices tab. Next, select this sink as the default for Spotify in the Playback tab (click the small down-arrow and choose Move Stream and then Null Output).

Icecast

You can run Icecast with a minimalistic configuration. I used the minimal example (/usr/share/doc/icecast2/icecast_minimal.xml.dist on Ubuntu) where I modified the passwords and the log directory (I set the log directory a directory where I have write permissions so that I can run Icecast as my own user). Start Icecast with

icecast2 -c icecast.xml

Gstreamer

Finally I take the spotify PulseAudio sink and channel it to Icecast by use of Gstreamer. The magic command is (in one line).

gst-launch-0.10 pulsesrc device=spotify.monitor ! audioconvert ! vorbisenc bitrate=300000 ! oggmux ! shout2send ip=localhost port=8000 password=PASSWORD mount=stream.ogg

The bit rate is set to the highest I could use without getting error messages (300kbps). I assume this is pretty transparent and does not degrade the 160kbps Spotify output much.

Now tune your Squeezebox to URL http://ip-address-of-linux-machine:8000/stream.ogg. Modify the file name and port according to your configuration.

Comments are disabled on this article due to problems with spam. Somehow spammers believe that link-spamming this page with praise for the article will send them lots of readers or google-points or something …

4 Responses to “Streaming audio from Spotify on Linux to Squeezebox”

  1. on 19 Oct 2009 at 13:45 1.jku said …

    Thank you! This is very nice and exactly what I was looking for.

    The only problem is GST+PA+Spotify using quite a lot CPU, about 30% on a 1.4Ghz machine (pushing the laptop above the limit of comfortable temperatures on the lap). I guess gst-launch-0.10 and spotify.exe using a lot of CPU is explained by the encoding and decoding. I have to wonder why PA uses almost 10%…

    In any case thanks a lot.

  2. on 04 Dec 2009 at 21:55 2.megsona said …

    Thanks for the guide, very useful.

    Rather than using Spotify with OSS however, I used this PPA for Karmic which has pulseaudio support compiled into it

    http://www.3spoken.co.uk/2009/08/making-wine-sound-work-with-pulseaudio.html

    So, I’ve now got my Spotify showing as a pulseaudio source but I don’t know where to find it’s .monitor file in order to follow the rest of your guide. I can stream all my system sounds (including Spotify) over Icecast by using

    gst-launch pulsesrc device=alsa_output.pci-0000_00_1f.5.analog-stereo.monitor ! audioconvert ! vorbisenc ! oggmux ! shout2send mount=/stream.ogg port=8000 password=pass ip=127.0.0.1

    but then I have the problem where my laptop audio is playing at the same time as my delayed streamed (to squeezbox) audio.

    Hope that makes sense, any thoughts?

    Thanks

  3. on 23 Dec 2009 at 20:08 3.use-lame said …

    Apparently, using vorbisenc the way you do in your post, gives me an 80kbps vorbis stream in mono. Using the following command to start gst-launch should render a 320kbps stereo mp3 stream (I tried to get stereo with vorbisenc, but couldn’t find any properties that did so). Anyway, here is the gst-launch command i used:

    gst-launch-0.10 pulsesrc device=spotify.monitor ! audioconvert ! lame bitrate=320 mode=stereo ! shout2send ip=localhost port=8000 password=PASSWORD mount=stream

    To use lame to encode the stream, you need to have the lame gstreamer plugin. To install this on Ubuntu (karmic), run:

    sudo aptitude install gstreamer10.0-plugins-ugly-multiverse

    Apart from this minor issue, I was able to follow your guide with no issues on Ubuntu Karmic, thanks for publishing it!

    (Note: I’m using the PPA wine patched for PulseAudio).

  4. on 11 Jan 2010 at 23:18 4.Bent Ole said …

    Tusen takk!

    I would of spent years figuring this out. :)

    Works perfectly.