Have you ever wanted to host your own radio station? I’ve always thought it would be really cool to have a self hosted radio station with multiple stations. Since I download a lot of music content from YouTube, why not put it in a playlist and stream it?

I’ve had a few attempts at this over the years, but could never really get the hang of it until recently. The last attempt was using Azuracast and although it is a great tool, it’s a bit complicated for my use case and getting the networking to work with multiple stations was a big hurdle to get around.

There is also the solution of something like Plex or Jellyfin to host the content and then just stream from there, but it isn’t really a “radio station” feel. There are a lot of neat controls around creating a radio station that this solution cannot give you.

My question was, “Is there a way to simplify the tool set and just have a more simplistic approach?” Well, the answer is yes!

Enter IceCast2 and LiquidSoap. In a nutshell, LiquidSoap is our “audio output client” that sends an audio stream to the IceCast2 server so that it can be broadcasted any way you want. Each stream that is sent to the IceCast 2 server can be accessed by a unique URL, as you will see shortly. LiquidSoap actually has a lot of advanced features, such as adding in Jingles, crossfading, normalization, and more. And the best part is that LiquidSoap has its own scripting language! Automation is always a plus with these small projects.

Goal

  • Finding the most simple way to take MP3 files and stream them for LAN or Internet access.

Pre-Requisites

  • This short tutorial has been test on Ubuntu 20.04 LTS and LAN only. I will possibly add instructions on getting this to be Internet accessible, but depending on your home lab setup, YMMV.
  • Both IceCast2 and LiquidSoap (from Ubuntu’s Repo) are installed. Installation instructions are out there if you have another distro.
  • IceCast2 needs to be setup and accessible. This include being able to access the web UI and having a stream username and password set.

The Script

First, let’s create the LiquidSoap script:

touch simpleradio.liq

Open this file in any text editor of your choice. Start by defining a playlist; this line looks at a folder, grabs all available files, and puts them into a new playlist. Don’t worry, non-audio and video files will be skipped over when this runs. Mode is set to ‘random’ because this is the way.

allmusic = playlist(mode='random', '/media/mymusic')

Next, let’s define a file to play if any problems should arise. This is technically optional, but you might as well throw something in there.

security = single('/media/mymusic/oops.mp3')
radio = fallback(track_sensitive = false, [allmusic, security]

Let’s also add some normalization of the tracks and some crossfading:

radio = nrj(radio)
radio = crossfade(radio)

Finally, let’s take the output from LiquidSoap and send it to IceCast2:

output.icecast(%mp3(bitrate=192),
  host = "localhost", port = 8000,
  password = 'MYSECRETPASSWORD', mount = 'simple-radio.mp3',
  fallible = true, radio)

Save and exit, then run the script:

liquidsoap simpleradio.liq

At this point, we have taken the playlist we created and are sending it to IceCast2 to distribute. How do we know that this is working? Go to the IceCast2 web UI, log into the Admin Home page, and you should see a new Mountpoint called “simple-radio.mp3”. From here, you can use your favorite media player such as VLC and open the network stream. For example: “http://192.168.1.100:8000/simple-radio.mp3”

Conclusion

This is just barely getting you off the ground as there are many possibilities. For example, you can run this LiquidSoap script via daemon, stream video along side audio, have jingles/bumpers sound off every X songs, take requests, and so much more. Please let me know what you come up with.

Here is a great link to someone that used IceCast2 and LiquidSoap to create a Lo-Fi radio station. It’s pretty rad!