Running your own radio station

The project's scope is to have your own radio station broadcasting live audio streams, either live, streamed via a UDP socket or just simple mp3 files.

KEYWORDS

  • Python
  • RaspberryPi
  • IceCast2
  • IceS2
  • OGG vorbis

Free HTML5 Template by FreeHTML5.coServer diagram

I stumbled upon the problem of broadcasting sound(live, prerecorded or just music) over IP on a one-to-many network topology and setup a nice solution that works on a generic server machine.

You can do this by hosting a digital radio server and broadcasting the sound; to get external access you'll need a real IP address or static DNS, you can get it from your ISP; in case you want to go public, a licence to stream audio will be required.

What you need to set this up wll be a audio server - I used IceCast2 - , you'll also need an audio feeder that will feed audio to this server, I used Ices2. Ices2 can either read audio data from disk (Ogg Vorbis files), or sample live audio from a sound card and encode it on the fly. I deployed everything to a RaspeberryPi 3+ running Raspbian..

Install IceCast2

update apt-get

$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo reboot
						
install necessary packages. Note: The names can vary slightly according to Linux distribution

$ sudo apt-get install libxml2 libxslt1-dev curl vorbis-tools libogg-dev libvorbis-dev libshout3-dev
						
for IceCast2 I downloaded this version: icecast-2.4.3.tar.gz untar and install

$ tar -xvf icecast-2.4.3.tar.gz
$ cd icecast-2.4.3
$ ./configure
$ make
$ sudo make install
						
Note:
I got an error here because of the XSLT lib, so I installed it again.
Err: “configure: error: XSLT configuration could not be found”
Fix: sudo apt-get install llibxslt1

edit the config file

$ sudo nano /usr/local/etc/icecast.xml
edit location tag:
	replace 'Earth' with something else
change port:
	<listen­socket> 
       <port>8003</port> 
	</listen­socket>
						
start icecast

$ icecast -c /usr/local/etc/icecast.xml
						
Note: I got some errors on this part:
Err: icecast error connection/connection setup sockets no listening sockets established
Fix: check if somebody else is listening on 8003
Check what's happening on port 8003:

$ netstat -tnlp | grep 8003
						
and kill it
OR
Replace 8003 with some unused port
you can encouter this error:
Err: FATAL: could not open error logging (/usr/local/var/log/icecast/error.log)
Err: FATAL: could not open error logging (/usr/local/var/log/icecast/access.log)
Fix: Create both files on the required locations

If everything worked fine you'll be able to access localhost:8003 and see this image:

Free HTML5 Template by FreeHTML5.coIceCast2 server UI

Ok, now we have the radio server up and running and waiting for some audio streams. To get the audio streams we have several options. I choose IceS2 which is a source client for Icecast streaming server. It's purpose is to provide an audio stream to IceCast. IceS can run on the same machine or a different one, so we can steam the data from the network.

Install IceS2

Now we'll install IceS2 and all dependencies

install ices2

$ apt-get install ices2
						
Note: it comes with sample config file in:
/usr/share/doc/ices2/examples/ices-alsa.xml
/usr/share/doc/ices2/examples/ices-oss.xml
/usr/share/doc/ices2/examples/ices-playlist.xml

create folder path setup

$ sudo mkdir /var/log/ices
$ sudo mkdir /etc/ices2
$ sudo mkdir /etc/ices2/music
						
copy template config file

$ sudo cp /usr/share/doc/ices2/examples/ices-playlist.xml /etc/ices2
						
edit config file

$ sudo nano /etc/ices2/ices-playlist.xml
						

changes to run in background:
<background>0</background>
To
<background>1</background>

changes to log in console:
<console>0</console>
To
<console>1</console>

point to the playlist file:
<input>
<module>playlist</module>
...
<param name="/home/pi/Music/playlist.txt">
</input>


create the playlist in /home/pi/Music/playlist.txt and add songs to it.

Note: IceS2 doaes not support mp3, so the playlist should contain for eg .ogg files.


run IceS2:

$ ices2 /etc/ices2/ices-playlist.xml
						

If there are no errors it should look like this:

Free HTML5 Template by FreeHTML5.coIceCast2 server UI

Get Started

If you need some guidance in engineering field or you're seeking for some help don't hesitate to write me.

Let's work together