REST service for multichannel audio on demand from Raspberry Pi. Made with ❤️ for makers, DIY craftsmen, and professional soundstage designers everywhere
Unfortunately, audio in linux is just kind of ... stupid. Over the course of many months, I have discovered that this service works best running as a non-root user -- so the installation process now prompts you for a user to run the service as (and it defaults to the current user, which is usually fine).
Pro tips:
- Make sure the user that the service runs under already exists and has access to the
audiogroup. (Thepiuser -- or whatever the first user is that you setup -- will be in theaudiogroup by default). - Be sure to set your default audio device using
raspi-config. - Also: set your volume using
alsamixer. - Don't try to run this as root. (Unless you want to be miserable). Because audio in linux is just stupid. Sorry about that.
I would recommend using the Raspberry Pi DigiAMP+ since it's now an official Raspbery Pi foundation product. Be sure to follow the Raspberry Pi DigiAMP+ installation instructions.
Hint: I used the following settings in /boot/firmware/config.txt at the very bottom
# Some magic to prevent the normal HAT overlay from being loaded
dtoverlay=
# And then choose one of the following, according to the model:
dtoverlay=iqaudio-digiampplus,unmute_amp
I have used a pair of Polk Audio M2 indoor/outdoor speakers with the DigiAMP+ and it's VERY loud. Use alsamixer to adjust volume of the speakers.
You can do a test with streaming music using ffplay -autoexit -nodisp http://ice1.somafm.com/u80s-128-mp3
I would recommend using the Adafruit Speaker Bonnet for Raspberry Pi as well -- just get a Pi with headers and slide the bonnet right down on top of it (and be sure to follow the Raspberry Pi OS configuration instructions for the board). I used a pair of 8 ohm 3" speakers with the bonnet and it's reasonably loud. Use alsamixer to adjust volume of the speakers.
You can do a test with streaming music using ffplay -autoexit -nodisp http://ice1.somafm.com/u80s-128-mp3
Make sure that you have a stock Raspberry Pi installation and make sure you have configured HDMI in your /boot/config.txt. Also: Buster might be a good legacy distro to start with. This option might be a little unreliable, depending on the HDMI cable and system you're feeding into.
You can do a streaming music test with the first HDMI port on the device (HDMI 0): ffplay -autoexit -nodisp http://ice1.somafm.com/u80s-128-mp3
Run speaker-test -c2 to generate white noise out of the speaker, alternating left and right.
Install Raspberry Pi OS (Bookworm or later) on your device. For best results, use the Raspberry Pi Imager and select Raspberry Pi OS (64-bit).
Install the prerequisite package repository (one-time setup per machine):
wget https://packages.cagedtornado.com/prereq.sh -O - | shInstall the fxaudio package:
sudo apt install fxaudioDuring installation, you will be prompted to specify a non-root user to run the fxaudio service.
- If you press Enter without typing anything, it will default to the current user (recommended in most cases).
- The specified user must already exist on the system and must be a member of the
audiogroup. (On a standard Raspberry Pi setup, the first user — such aspi— is already in theaudiogroup.)
Important:
- Do not run
fxaudioas therootuser. I cannot overstate this. Audio on Linux can behave inconsistently under root, leading to unreliable results. - Ensure your audio device is set correctly using
raspi-config, and adjust output levels withalsamixer.
After installation, the service will be running and available at:
- REST API:
http://localhost:3030 - API Documentation:
http://localhost:3030/swagger/
This is most likely your HDMI audio system doing something it shouldn't. You can work around this by enabling a service to play 'no audio' all the time in the background. This will keep the device ready for when you want to play some actual audio through it.
Put the following in /etc/systemd/system/aplay.service
[Unit]
Description=Invoke aplay from /dev/zero at system start.
[Service]
ExecStart=/usr/bin/aplay -D default -t raw -r 44100 -c 2 -f S16_LE /dev/zero
[Install]
WantedBy=multi-user.target
Then run the following commands to register the service, enable it, and start it:
sudo systemctl daemon-reload
sudo systemctl enable aplay
sudo systemctl start aplay
