Saturday, November 19, 2011

Ubuntu as a wireless speaker of iPhone using Airport (ShAirPort)

What I wanted to do at first was to use my PC speaker as a wireless speaker to play music from iPhone directly without any wiring.

My first idea was to use bluetooth.
I had a hard time to set this up and finally succeeded to make an audio sink from iPhone using bluez(
I could listen music with desktop speaker via bluetooth, but it was not so easy to make it running every time I want.

So I bought a bluetooth receiver.

This was very compatible and easy to use.
It automatically turned on only when it pairs with my iphone.
But I have not been using this because I was disappointed its sound quality.

Finally, I could do this with Apple's Airplay (
ShAirPort ( can make Ubuntu to emulate airplay speaker.
It seems to me that ShAirPort was implemented to use Apple's private key(, so please use this at your own risk.
Also note that this instruction is from in ShAirPort source.

1. download source of ShAirPort
Just click 'ZIP' icon, then you can download all source files in one zip archive.

I confirmed new version of shairport does not work with my fresh ubuntu 12.04.
I am not sure what has been changed, but old version of shairport still works on my fresh ubuntu 12.04.
If you don't mind, you may download old version of shairport below.
You may compile and run it as described below.

2. unzip

Open terminal, go to the directory where you stored the source file and unzip.

$ cd Downloads
$ unzip
$ cd albertz-shairport-83c1b71

3. Install followings

$ sudo apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config

4. Compile

$ make

Make sure that you have no error.

5. Run

$ ./

That's it.
Now see your iPhone and make sure that you have ios version 5 or later.
You may play it with iPad, iPod and iTunes also.

You should see a new icon when you play a music,
just select new speaker in that menu.

Pros :
- All you need is just local network between iPhone and Ubuntu
- No quality loss
- Easy to configure
- Only few resource consumption

Cons :
- Consumes wireless bandwidth (802.11n is recommended)


  1. I was using Totem with a plugin, but it worked only for video. This solution work perfectly for me and I can use my Ubuntu based media center as virtual "airport speaker" for my iPhone. Thanks for this tutorial !

    1. you are welcome...glad to hear this works for you...!

  2. Great post! Worked for me :)

  3. it works allright, but the sound is playing too fast =/ been googling like crazy after a solution.. anyone else had this issue?

    missing frame is also coming up alot, but the only notable issue is the "pitched" sound..

    1. Maybe your problem is related with the missing frame.

      You can check the network connectivity with
      $ ping ip-address-of-your-iphone
      from your desktop.

      (You may see the IP address of your iphone in settings -> wifi -> name-of-ssid).

      It depends on your wireless condition, you should have less than 5% of lost-rate (approximately).

      If you could verify some packet losses,
      - try to change your wireless channel to different channel in your wifi router
      - turn off channel-bonding if you use 802.11n

      Hope this helps...

  4. indeed, very easy to setup and run.

    Thx very much !

  5. Hey so for some reason it didnt work on my Ubuntu 12.04. This is the error it gave when i tried to run my script (and yes the make file did compile)

    Can't locate Net/ in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at ./ line 48.
    BEGIN failed--compilation aborted at ./ line 48.

  6. it's the same for me... on Ubuntu 12.04.1 it doesn't seem to work, solution? (very good article, nice work!)


  7. Thanks for information.
    I got same error on my fresh ubuntu 12.04, I do not know the reason.
    I also confirmed that the old version stored in my backup works correctly on ubuntu 12.04.
    So if you don't mind, use old one instead of new one in github.
    and let me know if you know the recent working version of shairport that works on ubuntu 12.04.

  8. The last version doesnt' work for me, but the old ones work perfectly!
    I'm using Ubuntu 12.04. :)
    Thanks !

  9. Just do an: sudo cpan install Net::SDP in the console to met the new dependencies requirements for Shairport.

  10. I can confirm that viniciusferrao is right. Seems so obvious now. I am on Ubuntu 12.10.

    I just did:

    apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi

    cpan install HTTP::Request HTTP::Message Crypt::OpenSSL::RSA IO::Socket::INET6 Net::SDP

    And the latest version of ShairPort builds and executes fine.

  11. It worked fine for me with a MacBook Pro client and Mountain Lion. However it failed with an iPhone 4S when starting to play.

    The following patch solved the problem:

    < my %sdp = map { ($1, $2) if /^a=([^:]+):(.+)/ } @sdplines;
    > my %sdp = ();
    > my $sdplin = '';
    > foreach $sdplin(@sdplines) {
    > $sdp{$1} = $2 if $sdplin =~ /^a=([^:]+):(.+)/;
    > }

    Thank you for your blog which was very helpful to me.

  12. THis happens as soon as I try to connect any device to the AirPlay.

    /albertz-shairport-83c1b71$ ./
    Etablerad under namnet "19218FE929A4@ShairPort 7758 on MEDIA"
    Odd number of elements in hash assignment at ./ line 631.
    Use of uninitialized value in subroutine entry at ./ line 632.
    avahi daemon terminated or 'avahi-publish-service' binary not found at ./ line 236.

  13. Can anyone please help me out with this error:

    /albertz-shairport-83c1b71$ ./
    Established under name '68615EC5F130@ShairPort 13675 on UbuntuLaptop'
    Odd number of elements in hash assignment at ./ line 631.
    Use of uninitialized value in subroutine entry at ./ line 632.
    no AESIV at ./ line 632.


  14. I get "Audio StreamWJQsH9Gp+CoiWav5ghqhQgFATAL: Could not open ao device" when I try to start playing audio from iTunes. I can connect fine, iTunes shows that I'm connected and shairport gives no errors when I connect, but it spits out this error when I try to start playing music, and no audio comes out of the speakers. Is there another program I need to install, or do I need a new sound card or something?

    1. Well, I managed to get rid of that error. I installed alsa-base and it turns out all of my outputs were muted. Now I can use aplay to play wav sound files with no problem, and shairport no longer gives me that error. However, there is still no sound coming out when I attempt to play music through iTunes. I know it's not a problem with my sound card or device settings, as I can play sounds with the aplay command.

    2. It finally works! Turns out my firewall was in the way of it. I had already opened 5002/tcp, but netstat -lnp | grep hairtunes revealed that shairport uses both 6000/udp and 6001/udp as well.

  15. this is awesome - but how do i make the sound output to my HDMI Audio Device instead of the default system speakers?

  16. Wireless Headset this is amazing headset made the plantronics, simple and best performance in a very short budget, excellent voice, no distortion, no noise.

  17. Buy & sell new and used iPhones.
    Wide selection of new and used iPhones for sale.
    More at this link

  18. I have some simple steps to save you a lot, convert your wired speakers to wireless. This is the article.