Raspberry Pi with Sonos S1

The Raspberry Pi, the ultimate in-home audio solution?

My situation

The Sonos Play 5 Gen 1 doesn’t have AirPlay support. It does Spotify Connect, but no AirPlay. While Spotify Connect is pretty good at just playing background music, there’s times that someone wants to play a song from SoundCloud, or YouTube, or some other service.

The solution

A Raspberry Pi to the rescue! This Pi is actually doing a lot at once - I already have raspotify and shairport-sync to add AirPlay and Spotify Connect to a Bose SoundDock connected via a 3.5mm audio cable.

Because Sonos speakers can be managed over Wifi, I can actually have the physical jack be used for the Bose speaker, and a separate AirPlay target for the Sonos speaker.

The setup

  1. SSH into your Raspberry Pi.

  2. Set up an airconnect directory with

    cd /var/lib/
    sudo mkdir airconnect
  3. Get the files from philippe44’s AirConnect Github repo with

    cd ~
    wget https://github.com/philippe44/AirConnect/releases/download/1.7.0/AirConnect-1.7.0.zip
    sudo mv AirConnect-1.7.0.zip /var/lib/airconnect/
  4. Unzip the files with

    cd /var/lib/airconnect/
    sudo unzip AirConnect-1.7.0.zip
  5. Give the binaries executable permissions with

    chmod +x /var/lib/airconnect/*
  6. Create a service file with

    sudo vi /etc/systemd/system/airupnp.service

    and paste in the following:

    [Unit]  
    Description=AirUPnP bridge  
    After=network-online.target  
    Wants=network-online.target  
    
    [Service]  
    ExecStart=/var/lib/airconnect/airupnp-linux-arm -l 1000:2000 -Z -x /var/lib/airconnect/airupnp.xml   
    Restart=on-failure  
    RestartSec=30  
    
    [Install]  
    WantedBy=multi-user.target   

    Some things to note:

    • You might have to change the directory if your folder isn’t /var/lib/airconnect/

    • There’s a -l 1000:2000 flag. This adds some latency to the audio, but it’s recommended from the Github page.

    • You can use nano if you don’t like vi. However, you should be aware that vi is superior in every way. Make sure to :wq when you’re done.

  7. Register the service with

    sudo systemctl enable airupnp.service

If you don’t need to change the name of the speakers, skip to 10.

  1. (Optional) Create the config file from the binary with

    /var/lib/airconnect/airupnp-linux-arm -i airupnp.xml

    Note, run this command in a directory you’re allowed to write files to. Otherwise, it’ll give a segmentation fault.

    I moved my airupnp to the /var/lib/airconnect/ folder, and then edited it.

  2. (Optional) Edit the config file with

    sudo vi /var/lib/airconnect/airupnp.xml

    In here, you can change the names of speakers. I changed the speaker in the Kitchen from “Kitchen+” to “Kitchen Sonos”.

  3. Start the service with

    sudo service airupnp start

The result

The Sonos speaker now shows up as an AirPlay target, and can be used to play audio from any AirPlay device. There’s a second of latency between pressing play and the audio starting, but it plays music just fine.

This entire process shouldn’t take more than 15 minutes of tinkering, but I have had experience with sshing into my Raspberry Pi, and I have already had to deal with services and config files with raspotify and shairport-sync.

Update 01-30-2024

Running raspotify and airupnp at the same time seems to break raspotify’s audio out. (It’s silent).

Update 02-05-2024

It turns out the speaker’s volume was really low when I tried it. Raspotify, shairport-sync and airupnp work fine together.