BaReinhard's Tech Blog

A blog of various technologies, largely based around the Raspberry Pi.

Follow me on GitHub Follow me on Instagram

Multiroom Audio using Chromecast Audio's + the Raspberry Pi for iOS Support

Good Morning Folks, I know it has been a while since my latest blog post, chalk that up to several projects (the one I’m talking about today) and learning a few new JavaScript Frameworks for my internship training. Anyway, without further adieu I would like to introduce you to a new project that I have finally configured to my liking. While it is not an extremely intricate project like my last one it actually works extremely well and keeps the price of multiroom audio to something thats affordable even for your average college student.

Multiroom Audio with iOS/Android Support

Well to be honest, I didn’t actually do anything to support Android devices but from what I understand (as I don’t have one to test with) Android devices are natively supported by chromecast audio devices and work in a similar way that iOS works with AirPlay supported devices. The one thing I did get to work was to get AirPlay to stream to multiple ChromeCast Audio devices without too much of a lag (You can expect 3-5 seconds between device start and audio playback, but once audio starts there isn’t any chopping or reverberations).

Whats needed?

  • 2+ Chrome Cast Audios, it will work with one but then its not really multiroom
  • Raspberry Pi 3 (It also would work with a Pi 2, but isn’t supported for other versions)
  • microSD Card running Ubuntu MATE (this is why only Pi 3 and 2 are supported, it could be possible it works on a Zero but I haven’t tried)
  • Keyboard and Monitor (since Ubuntu MATE has a setup process and doesn’t directly allow for a ssh out of the box)
  • Ethernet Connection ( You could possibly get away with onboard WiFi, but I would assume that the playback latency would be greater)
  • Speakers ( this is likely the most expensive part of the project, depending on what you want out of your sound will dictate your audio setup here)

How do we get started?

Well its really quite simple due to my latest pull request as of last night. After you have your microSD card setup with Ubuntu and have finished the setup process that comes with Ubuntu MATE we can begin by opening up a terminal by simply pressing ALT+T.

Once the terminal is open we will start with a bit of prep work by installing git and once that finishes start with the installation process

sudo apt-get install git -y
git clone https://github.com/bareinhard/Multiroom-Audio-iOS
cd Multiroom-Audio-iOS
sudo chmod +x install.sh
sudo ./install.sh

During the install it will prompt your for your user name, this is important that you enter the correct username for AirPlay to work correctly.

What is your username? : (your username here)
User name is : (your username here)
Is this correct? (y/n) : y

From there is will begin the remaing prep work such as adding repos for pulseaudio-dlna and shairport-sync, there are a few times you will need to hit enter to accept the added repositories, the project will prompt you to restart afterwards (it is suggested you do so)

Upon rebooting your chromecast audios should appear as sinks through pulseaudio via pactl list sinks

At this point you will want to download the Google Home app if you don’t already have it. Create all the necessary groups of Chromecast Audio devices by clicking on the settings of a device and choose ‘Add Group’.

Once you do this you can view the added groups in your sinks again via pactl list sinks

Now comes the fun part, connect your iOS device to your new AirPlay Device and start streaming audio. I am aware no sound is coming out yet, because we haven’t told it to move the audio to the chromecast sink yet. You need to manually do this for now, I am working on a script to automate this process and should be available in a couple days.

pactl list sinks                #Mark down the number of which sink you will want to output audio to
pactl list sink-inputs          #You may need to run this command a few times (there is still a bug where the sink will change its Sink Index, this will be a non issue with the automated script)
pactl move-sink-input (index number of sink input) (index number of sink output)

After all that, it should now be streaming to your audio sink.

As a note, I have found as long as you don’t reboot your Pi you will not have to run the above commands, but you will on each reboot.

If you would like to change your AirPlay Devices name you can do so by editing /etc/shairport-sync.con

sudo nano /etc/shairport-sync.conf

The technical bits

Essentially, what this project does is uses pulseaudio to control the sound to the chromecast device. Pulseaudio-dlna allows for UPnP devices on the network to show up as Pulseaudio sinks. We run shairport-sync as a user level process so that it has the same pulseaudio session that ubuntu uses at desktop login. We also have shairport-sync run as alsa output using the pulse plugin for alsa, which allows for the input sink to show up in pulseaudio. I will likely be using shairport-syncs built in script caller to enable auto sink connection, but will update this as that aspect gets finished.

Hope you enjoy the multiroom audio!

Brett