PulseAudio: Sound over the network

Update 1:
I added the package dbus-x11 which needs to be manually installed for this to work on a system that has no X server.

Update 2:
I added a tunnel setup that I got from a helpful person on pulseaudio's IRC channel.



It may have taken me years, but finally I got around to implementing this and it works, easy. About a decade ago, in the days of OSS I once even tried to export /dev/pcm using NFS.. I know, it was funny though.

Sound Server Setup

I am using a Raspberry Pi that I was offered by a friend (because I had gotten technically older) but I am sure this should work with any computer. I am using the default Raspbian image. I would say you should already have sound working on this computer. Then install a few new things: apt-get install pulseaudio pulseaudio-module-zeroconf avahi-daemon dbus-x11

Then edit /etc/default/pulseaudio and change PULSEAUDIO_SYSTEM_START from 0 to 1: PULSEAUDIO_SYSTEM_START=1

Tell PulseAudio to listen (lolpunhaha) to network connections by adding the following 2 lines to /etc/pulse/system.pa (adjust the subnet to whatever you need): load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/24 load-module module-zeroconf-publish

You could either restart PulseAudio or just reboot the whole thing if you're lazy.

Sound Client

As usual I am using Debian, in this case Wheezy, hence maybe a standard Squeeze may not work with this (I haven't tested yet).

We need to change a PulseAudio client preference, and because this is a desktop I don't mind resorting to a GUI, so I installed paprefs: apt-get install paprefs

Run paprefs and under the "Network Access" tab there should be an option called "Make discoverable PulseAudio network sound device available locally", activate that.

Then all is left is to restart PulseAudio on the client. The easiest way is to reboot the whole system, but really.. really ? You could just kill and start your PulseAudio session thing: pulseaudio -k pulseaudio --start

Sound Client 2 - using a tunnel

In some cases the above doesn't work so well, there may be some lag, the server might die, etc. On IRC a very nice human told me I could set up a tunnel from the client to the server. So I did that (with much help). It's now been more than a few months and everything is okay. I had testing versions of Pulseaudio to achieve this (client needs to be version 5+, the server can be older), but since Debian stable is Jessie, everything is back to be being kosher (stable).

In /etc/pulse/default.pa I added (where 192.168.0.1 is the PulseAudio server): load-module module-tunnel-sink-new server=192.168.0.1 sink_name=Remote channels=2 rate=44100 This means that we let go of automatic discovery and tell the client where the server is. I consider this a workaround for what PulseAudio promises, but in practice this works well (you just need to keep IPs as static as can be).

No More Playing with Audio Cables !

Now via pavucontrol I can send the sound to the Rapsberry Pi which is connected to the speakers or switch them back to use my laptops system. Same for others here, we're all connected to the main speakers so no need to pass the cable around the table.

comments:
avatar

chris

i had alot of problems with the sound quality so i put my Laptops IP Adress instead of the whole subnet in the line "load-module module-native-protocol-tcp auth-ip-acl=x.x.x.x"
avatar

manu - http://manurevah.com

Thanks Chris for that, I'm going to try that out as I've also had some quality issues, more like "lag" and such.

Cheers,
avatar

Jean - http://alsageek.fr/

I found here exactly what I expected to find on Internet : a simple but nicely documented way to render music from my laptop to my now "open-airplay" system ! Thank so much :-)
avatar

Jocelyn Delalande - http://jocelyn.delalande.fr

Excellent article. Just works. Unfortunately for me, this solution is quite bad over wifi.

Two precisions :

Actually, you don't have to restart pulseaudio after changing settings on client.

And if you are using gnome (or a desktop with session processes handler), `pulseaudio -k` is sufficient to restart pulseaudio.
avatar

Conker

Hi there!!
I've a question, in my server, I installed Debian Jessie, where can I find the file that you say on the second step (/etc/default/pulseaudio)?
Thanks in advance!
avatar

manu - http://manurevah.com

Hey Conker,

Sorry for the late reply.

It appears that /etc/default/pulseaudio is no longer present in Debian Jessie, I think you can ignore that step.
avatar

Claudia - http://www.behance.net/claudiaalvarado

Thank you for your post. Do you happen to have set up instructions for using RTP? I am having issues with the packet sizes being mismatched between the client and server and am unable to stream audio. Any ideas? Thanks again!
avatar

manu - http://manurevah.com

Hi Claudia,

I'm not sure I tried the RTP method, or I didn't get good results. It's been a while I've not worked on this. If I do one day, I'll let you know, if you do, let me know.

Have you tried both methods mentionned in this howto ?
Leave a comment
You may use the following HTML tags: <p> <a> <strong> <b> <em> <i> <cite> <blockquote> <code> <pre>

Your comments WILL NOT be submitted to any third party (not even for anti spam verification).