Episode: 3014
Title: HPR3014: A Headless Raspberry Pi Streaming Radio
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr3014/hpr3014.mp3
Transcribed: 2025-10-24 15:09:53

---

This is Hacker Public Radio Episode 3,014 for Thursday, 20 February 2020.
Today's show is entitled A Headless Raspberry Pi Streaming Radio. It is hosted by John Kulp
and is about 18 minutes long
and carries a clean flag. The summer is.
I use a Raspberry Pi to make a streaming radio device for my pillow speaker.
This episode of HPR is brought to you by AnanasThost.com.
Get 15% discount on all shared hosting with the offer code HPR15. That's HPR15.
Better web hosting that's honest and fair at AnanasThost.com.
Hey everybody, this is John Kulp.
I'm Luffy at Louisiana and I'm going to talk to you today about a recent project that I've done that I'm very, very happy with.
It has to do with a Raspberry Pi and I know a lot of HPR people use Raspberry Pi for all kinds of different things.
Hopefully this will be of some interest.
This morning I'm at the office. I finally got a little bit of time to do this.
Actually, what I'm doing is I'm procrastinating because what I should be doing is grading the exams that I gave yesterday
in my music history class. But I don't want to do that yet.
So I'm here on a Saturday morning recording an HPR episode before I try to do a little bit of grading.
I don't think the students really expect to have the grades posted until Monday anyway.
So I've got a little bit of time.
So start off with I'll talk about the issue that I want to address.
And that is for years, for years and years, I've liked to have some kind of music or audio going while I sleep at night.
And when I was in high school college, what I would do is if I had a bedroom to myself, I would just turn on the stereo and play your tapes on loop or the radio or something.
And after I got married, I had a spouse who does not like to have anything going in the bedroom at night in any kind of audio.
She doesn't like that. And so what I found at one point, a device called a pillow speaker that somebody was marketing.
And I bought it and it's just a stereo mini plug on one end that goes into a couple of speakers enclosed in cloth.
And it would just slide under your pillow and you could lie down on your pillow and you could hear it, but your partner in the room could not.
And that worked very well and it worked. I used that for quite a long time and then it broke.
I don't know, wiring got moved around one too many times and it stopped working right.
So after that, what I did was I just took pairs of headphones that it stopped working in one side and I would just use those as stuff I had like a little earbud or something under the pillow.
And that would supply me with the audio.
And you know, it's not a great sound, but it's just enough where it will help me go to sleep.
Or if I find myself within Somnia during the night, I can lie there and listen for a while and be somewhat entertained and hopefully go back to sleep sometime after that.
So what I'm using the Raspberry Pi for is to give an audio source.
For the longest time, what I used was, well, first I started out with a clock radio that had a headphone output jack.
And I would just listen to either AM or FM radio, whatever station I wanted to listen to.
I would just turn the radio on and it would go through the earbud that I had under my speaker.
I went through a couple of clock radios. The last one was a memory device that had stereo output and it was okay, but I got where I didn't like it because something the way it was constructed was it was out of some kind of like soft rubbery kind of plastic on the surface and it got it real tacky and sticky.
I didn't like touching it anymore so I gave it the goodwill.
And so since then I haven't had anything for a while I would use my phone to stream some kind of audio source like my favorite is ESPN radio ESPN is the entertainment sports programming network goes back all the way to the late 70s and it's a sports thing.
And now it mostly has sports talk or sometimes it'll stream play by play action for live sporting events and stuff like that.
Excuse me, sorry about that.
The problem with using my phone was that in the morning when I got up I would like to grab my phone to put in my pocket.
And I would pull out the plug for getting that I needed to stop the radio before I did so or else the radio would just keep playing over the speaker and that would wake up my wife and she'd be unhappy with me.
And so I wanted a standalone device to stream the radio and so for a while then I used these little portable radios that I've got little Sony Walkman AMFM radios.
And they work okay but again you can only use over the air radio and they run on batteries and so I'd constantly have to recharge these rechargeable either AAA or AA batteries depending on which radio I was using.
And so I thought man I wouldn't it be cool if I could just set up one of my spare Raspberry Pi's of which I had three there were three Raspberry Pi's just sitting in a box doing nothing.
I should set one of those up to be a device to stream radio and it would have happened a lot sooner if I'd been able to find the right URL for the radio stream that I wanted which was ESPN radio.
It used to be not that hard to get that back in I don't know seven or eight years ago it seemed like they would just publish the URL for the MP3 feed and you could use any number of things to stream it.
But nowadays you can you can stream ESPN radio just fine on their website but they bury the URL somewhere deep in some kind of script and it's really hard to get to.
But I recently decided to give it another go and I found the URL by using a little helper app on the Firefox browser.
There's an extension called video download helper and most people use it to find the address of videos so that they can download them and view them offline.
But it also works to find the URL just about any media that's playing on the page and so when I went to the ESPN radio playback website I think it actually redirected to tune in and played the station.
And then I clicked on the little video download helper icon and followed little menu links to find a URL that what that told me was the URL for the audio that was playing and then I found when I went to a command line and typed in CVLC that's the command line VLC version followed by that URL it actually played the same radio stream.
And so that's that was like the missing piece I needed to be able to set up a headless Raspberry Pi next to my bed and have it play ESPN radio for me.
So I guess a little bit about the hardware I'm using a Raspberry Pi model to Raspberry Pi 2 model B. So I believe it's the one that's got one gigabyte of RAM and a slightly better processor than the original Raspberry Pi had.
The other two pies that I have were the earlier one with only 512 megabytes of RAM.
And when I've used the Raspberry Pi before for various applications I'd always put raspy and on it but this time I decided to try Ubuntu server.
And so that that actually went really smoothly. There's a there's a page on I don't know the Ubuntu website or somewhere or maybe some I forget where I got the instructions but it's very very easy to get the Ubuntu server onto your Raspberry Pi
and get it running.
I had to do a couple of things to get the Wi-Fi working I use a little Wi-Fi adapter called let's see it's a panda wireless USB Wi-Fi adapter.
I think it was one of those ones that the one like eight of fruit industries or someone like that recommended for use with the Raspberry Pi.
It was maybe ten or twelve dollars and I found a webpage somewhere where somebody gives you the code that you need to put in the slash Etsy slash interfaces configuration file and then also in the WPA
there's a subsequent configuration to make it automatically connect to your Wi-Fi network and that was also very easily done.
What else I use I did not use the default audio output on the Raspberry Pi it does actually have a 3.5 millimeter output socket but I use a USB audio interface that was also maybe eight to ten dollars
and I've got a link to that in the show notes to show which one I use because it seems like at least with the original Raspberry Pi the audio quality was very uneven.
Sometimes it was just straight up terrible and other times it was okay but with this very cheap USB audio interface the audio sounds great.
And so I set up the Raspberry Pi to connect automatically to my Wi-Fi network when it's turned on and then once I found the URL for the radio feed that I wanted I would save that in a script in my home bin.
So the home binary folder and make sure that that folder is in the path for my user.
And the player that I use is not I mentioned C-VLC for testing the audio URL and that work fine but I wanted something that did not pull in a bunch of dependencies the way VLC does when it does when you try to install it because I really wanted no graphical interface to be installed.
And so what I used instead is a package called MPG123 and that is an excellent little command line player that can play any kind of audio file and it can also play audio streams.
And so I see that the command that I put in the show notes here is MPG123-Pulse and I must have also had to install Pulse Audio in order to make things work correctly.
I forget exactly what was not working before I installed Pulse but anyway Pulse doesn't pull in too many packages and it all work fine.
I didn't want to get the system to bloated because I was using only a four gigabyte SD card to run for the whole thing.
So the command to play the audio stream is MPG123-PulseSpace-Q that's the quiet flag and then a space and that's followed by the URL for the feed.
And then I put another space and an ampersand so that it will run this in the background and go back to the command prompt.
And that worked just fine.
So once I had gotten it where I could make the Raspberry Pi play the stream I wanted, I saved those audio, you know, the stream playback commands into little scripts, just very, very like one line bash scripts with the name of the radio feed that I wanted.
So this one is called ESPN and when I type ESPN it runs that command. So I'm going to do it right now just from my laptop.
This is not from the Raspberry Pi that's at home. I'm in my office right now but this does the same thing. So I type ESPN press enter.
And you can hear the guys talking heads talking about sports.
Okay, and then at least one of them on my laptop I can do control C to get out of it or if it was running in the background the way I stop it is P kill space MPG and that will kill whatever process is associated with MPG.
There's also the local public radio station here, KRVS that's right here on campus down the road about three blocks from my office by type KRVS press enter.
We hear this is Saturday morning so we hear Zydeco music.
Okay, and I've got a few other radio station I worked at in Austin, Texas KMFA is a classical station.
I do P kill MPG to kill that one. Okay, so I've got four or five different streams set up most of the time I use ESPN radio but I do like other things and so I've got several different radio feed set up as scripts.
Most of them just have four letters the call number call letters for their stations that I can easily remember because I'm familiar with the stations.
So the Raspberry Pi is running headless with no keyboard or anything attached and I've got it I put a couple of pictures in a little photo gallery for you and I've mounted it on the back of my bedside table.
I've got a little night stand next to my bed and I mounted it on the back by putting the Raspberry Pi inside its little case and then that is inside a Chinese takeout container that is stapled to the back.
It's pretty low budget but it works well and you might be amused to look at the picture of that.
So the power source plugged into the power cable goes around the back of the night stand and into the wall and then on the other side is the audio cable that goes out and under my pillow.
So that works really really well to play the radio now in order to start the radio stream going since there's no keyboard attached I have to SSH into it.
So I could use either my laptop or I use my phone using an app on Android called connect bot and the connect bot is a little terminal emulator that you can use to SSH into stuff.
So I saved the connection info for the Raspberry Pi as one of my presets and it logs right in because I use SSH key authentication.
So I can log in on my phone and type the command to start ESPN radio and then just put my phone down and it starts playing the radio stream.
Now one other thing that I did to this since I wanted to be able to listen to ESPN radio ESPN radio it more times than just when I was lying down in bed.
Instead of going directly out of the audio interface to my pillow I put an audio splitter there and so the splitter one half of the splitter will go to the earbud that's going to my pillow.
And the other half I have going to a little FM transmitter that I use I used to use it plugged into my satellite radio so that I could have that broadcasting to my little portable radios that I carry around on my belt and listen to stuff.
And so one half of the splitter goes to the pillow the other half to a little FM transmitter by sea crane.
I've got a link to it in the show notes so you can look at it if you want but it's the same kind of device that a lot of fitness clubs use when you're on your ellipticals or exercise bikes or whatever and you've got like eight TVs in front of you showing different TV channels and they'll have little radio call numbers for you to tune in if you want to hear the audio for the TV.
Well on the back of those TVs will be a little FM transmitter that tells you what frequency and that broadcast at whatever frequency so mine broadcast at a certain unused frequency locally so that I can listen on my little portable AMFM radio to the feed so I can walk all around my house it goes all around my whole house and plus a little bit out in the yard I can hear the ESPN radio feed.
Now we do actually have a local ESPN radio affiliate here in Lafayette, Louisiana but at least half of the time they don't have the national feed that I like to listen to they've got local guys talking about local sports issues which sometimes are interesting to me but most of the time I'd rather hear what they're talking about nationally.
Is there anything else to talk about this I don't think so that that's pretty much it so I hope you found it interesting that this is how I'm using my Raspberry Pi now I'm glad to put it back to use because for the longest time I had three Raspberry Pi is just sitting in a box not being used for anything so now one of them gets used pretty much 24 seven streaming radio content.
And so I think that's that's pretty much that I hope you guys enjoyed that and I will talk to you again about some other topic this has been John Colp in Lafayette, Louisiana, bye.
I hope you guys enjoyed this video and I hope you guys enjoyed it.
Today's show is released on the creative comments, attribution, share a light 3.0 license.
