Streaming Audio Using Darkice
It is easy to use a Raspberry Pi to stream audio to your own webserver (running on the RPi) or using a global site such as Broadcastify. Though I used a RPi to build this, it is not unique to the RPi and can run on a variety of systems (I have used the same setup on my Ubuntu laptop).
Here’s what you will need:
- Raspberry Pi (any will work but I use a RPi4 with 4GB RAM)
- USB Audio Dongle
- Speaker to Line Audio Converter (build or buy)
- Scanner (or other radio output device)
- Assorted audio connectors and cables
- An Internet connection of course
- You have a working knowledge of installing the Raspberry Pi Operating System and can access it on your network or directly from a console setup
- Your scanner or radio receiving device works and has an antenna and can receive the frequency or range you wish to broadcast
- You are able to open a port for port forwarding on your Internet router to the port running Icecast (if you want to open the server to the world)
First, get your Raspberry Pi set up however you like with the Raspberry Pi Operating System according to the instructions found here (or using your own method). The instructions here should work for pretty much any modern Debian-based Linux distribution.
Now for the hardware setup. Your scanner or radio’s audio needs to be taken down from speaker level to line level. They do make converters you can buy such as these on Google. But you can also build one. I used this design found here with two 3.5mm jacks for the connections:
One note on this, it assumes your scanner is mono so no reason to use a stereo 3.5mm plug. Here’s my built version on the above diagram:
On an older version I had a commercial converter shows in this picture:
Now let’s put it all together with the USB Audio device inserted into the RPi and the microphone jack running through the speaker to line converter to the speaker out jack of the scanner. By the way, this setup is in my laundry room because it is opposite the ham antenna side. There will still be some de-sensing on transmit especially with these older scanners. There is an external discone antenna it is connected to (see BC760XLT Scanner Repair for the background story).
Now we move on to the software side of things. Boot up your RPi and once you have the system up and running how you like it, install Darkice via the command:
sudo apt-get install darkice
You will need to create/modify the Darkice configuration file. The default location is in /etc but you can specify an alternate location when you run the darkice command to start your streaming.
There is a great darkice.cfg example at the following link which is the one I used as my starting point on the Raspberry Pi:
You will need to sign up for a Broadcastify feed provider account and get the “mountpoint” and “password” from your account page and input it in the configuration file. Also note you may have to change the configuration slightly depending on your hardware. I had to change the “device” setting to “hw:2,0” and “sampleRate” to “44100” based on my configuration. You can view your hardware location via the “aplay -l” command. NOTE! When I rebooted headless (no monitor) the HDMI connection changed the hardware ports, so be aware this might happen.
Similar to the issue described on the page linked above, Darkice does not reliably restart on reboot. I’ve tried various configurations, running it as root, etc. and nothing has proven effective. If I find a solution I will post it.
Darkice should be run as a normal user, not root. The reason for the comment here is that when you run it as a normal user it will tell you try running as root, that is not needed.
If all is well, run darkice from the command prompt and your feed will show active over at Broadcastify! As I said before, you might have to fiddle around with the sample rate or other settings to get it just right for your configuration. For reference, here is how I start my Darkice instance:
nohup darkice -c /home/pi/darkice.cfg &
The “nohup” signifies No Hangup which leaves the process running after I log out. The “-c” specifies the configuration file and the “&” means run as a daemon/background process. Since I run headless, I ssh into my RPi and start darkice this way from my remote terminal.
BREAK BREAK BREAK… Okay you are done if all you wanted is a Broadcastify feed. But some have asked how you would host streaming audio on your own. the following section describes the additional steps which will be needed to do this.
If you want to run your own server you can install Icecast2. Darkice will feed to Icecast. Install Icecast using apt:
sudo apt-get install icecast2
Icecast will install in /etc/icecast2 and run the auto configure program for you. Be sure to remember your passwords as you will need the source password in the darkice.cfg file. The port you choose to run on (default 8000) is the one you will point your browser to on the RPi IP address. You can always edit the icecast.xml configuration file found in the installed directory mentioned above. Another good install document can be found here. Once you have finished the configuration, run:
sudo systemctl start icecast2
You can always replace “start” with “restart” or “stop”. You can also enable it to always run on reboot with “enable” (or do the opposite with “disable”). Once running you can point your browser to http://yourRPiaddress:port where that is the RPi’s IP and port number you chose in the setup. If you are local, you could use http://127.0.0.1:8000, for example. You should see this:
If that page came up, great news you are almost there. The next step is to feed Darkice into Icecast. You do that by adding an Icecast section to the darkice.cfg file using the password you set up in the Icecast installation for sources. If your darkice.cfg has an “[icecast2-1]” section already you can edit it, otherwise add the following, tailored for your installation:
bitrateMode = abr # average bit rate
format = vorbis # format of the stream: ogg vorbis
bitrate = 96 # bitrate of the stream sent to the server
server = 127.0.0.1
port = 8000 # port of the IceCast2 server, usually 8000
password = SOURCEPWD # source password to the IceCast2 server
mountPoint = KC4RCR # mount point of this stream on the IceCast2 server
name = DarkIce
description = KC4RCR Scanner Traffic
url = http://www.kc4rcr.com
genre = Mostly 2 meter ham repeaters around the VA area
public = no # advertise this stream?
Now restart the service using sudo systemctl restart icecast2 if applicable and go back to your web browser and reload the Icecast page. You should see something similar to the following:
You can also login via your admin password (username admin) and see the stream stats and listener info. It is just one mount point here so that’s all that is displayed. Icecast supports a variety of configurations if you are interested. Visit icecast.org for more information.