Streaming lullabies with a Raspberry Pi Zero
Bedtime Music
When a much-loved stereo bites the dust, a Raspberry Pi Zero fills in.
When my wife was young, she bought what must have been a pretty cool radio, CD, and dual cassette player stereo (Figure 1). The stereo worked well during her youth and her college years, and once we were married, she let the children listen to it.
Eventually, age began to catch up with this venerable system. First the cassette players stopped working, then the CD player would only play intermittently, and finally the tuner just stopped over the holidays.
My children like to listen to music as they are falling asleep, so I set out to look for a replacement. With so much music available on the Internet, I thought their radio could be replaced by a computer, which would offer extra flexibility because I could control it from my laptop. The computer could be scheduled to shutdown after the kids were asleep, rather than staying on all night.
I used this as an opportunity to get the new Raspberry Pi Zero WiFi and build up a small streaming solution that can be controlled from a laptop, tablet, or phone.
The Task
The task was to install Linux on the Pi, connect it to the network, install software for playing streaming music, and create a few scripts to tie everything together.
The solution is a small web browser that serves up a page that lets the children select the music they want to play while they fall asleep (Figure 2). I didn't want to leave anything to chance, so the solution will do more than just stream music. It will stop playing the music after 30 minutes and will play white noise for another 30 minutes after the music ends. Additionally, I wanted the ability to play white noise by itself if necessary.
The first step was to get a list of URLs for streaming sources. The Internet is full of streaming services, depending on the type of music you are interested in. I found a couple of free links from Minnesota Public Radio. The program MPlayer lets you play streams by just passing in the URL; for example:
mplayer http://choral.stream.publicradio.org/choral.mp3
So at this point, I knew where to get the music streams and what software to use to play the stream. I had a computer to play it on and an operating system to run on the computer. The next steps for creating my radio solution were:
- Download the OS
- Install the OS to an SD card
- Configure the Rasp Pi
- Connect a pHAT DAC to the Rasp Pi and configure it
- Install all software
- Configure Apache
- Program the solution using HTML and shell scripting
The first step was to set up the Raspberry Pi.
Setting Up the Pi
Installing the OS on a Raspberry Pi is just copying an operating system image [1] to the SD card using either dd
[2] or one of the programs to simplify the process for users not as comfortable with the command line [3].
Configure the Rasp Pi
I connected my Raspberry Pi to my network and booted it up. Once the SD card was resized, I configured all my personal customizations:
- Connected to my WiFi
- Reset pi user password
- Set hostname
- Set to boot to console
- Set locale and keyboard
- Set time zone
- Enabled SSH
One final thing you should probably also do is add the following line to the crontab
file for the root user:
@reboot /usr/sbin/ntpd -q -g
This line will ensure that the time on the Rasp Pi is updated to the current time from the Internet when it boots up.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.