STLs and Raspberry Pis
It’s a weird one. When it first came out, people were struggling to figure out what to do with it. A surprising feature for something that sold out very quickly – the Raspberry Pi.
Well, we’ve now come up with another use for them – it could replace your current STL codec. No, really. We’ve got a hospital radio station that’s looking to replace an old twisted pair line with an ADSL line for cost reasons. Admittedly the Barix Extreamer is very nice but a bit costly for our purposes. On top of that, we can configure the Pi to have some more complex fallback and alerting options with the LiquidSoap software. And that’s what I’m going to talk you through – setting up a Pi as a remote end codec.
So, without further ado:
- Acquire a Raspberry Pi. Purchasing one from CPC/Farnell is much more appreciated than nicking one from your colleague.
- Install Raspbian. It’s not that complicated and there’s a lot of guides out there.
- However, when you get to the installer wizard bit, we want as little RAM as possible for the GPU (I don’t know of many codecs that need 3D graphics with fancy shaders), to turn off boot to desktop, to set a sensible password for the pi account and to enable SSH.
- Fire up your Pi and install LiquidSoap. The command is literally apt-get install liquidsoap
- If you’re pulling an MP3 stream or planning on using MP3 backup audio, you’ll need to install some of the LiquidSoap plugins.
Create a file called /home/pi/stl.liq and bung in the following contents:
# STL Liquidsoap Config
# Logging
set(“log.file.path”, “/home/pi/log/liquidsoap.log”)
# Setup our sources
main_url = “http://yourserver:8000/stream_name”
emergency_audio = “/home/pi/emg.wav”
# Now our e-mail alert routine
def silenceHandler()
system(“/home/pi/mailsend.pl”);
end
# Our main source is streaming with silence detection
radio_stream = input.http(main_url)
radio_stream = on_blank(silenceHandler, radio_stream)
# Fall back to an MP3 file
# Also worth noting, if we get this far, we ought to tell someone (if we can)
emg_file = single(emergency_audio)
radio_stream = fallback(track_sensitive = false, [radio_stream, emg_file])
# Finally, pump it out the soundcard
output.alsa(radio_stream)
- Add a line to /etc/rc.local before the exit command with the following:
sudo -u pi liquidsoap /home/pi/stl.liq &
That will start LiquidSoap on boot – awesome. - Copy a backup audio file to the Pi. On this system we called it emg.wav. You can call it whatever you want but you will need to change the above script.
- Run alsamixer and bump the levels all the way up (for most installs).
Reboot and you’ll have a little codec. Try pulling the network lead out and seeing what happens.
So, that’s is all configured and running but what does it do. Well, by default it will pull a web stream from the URL of your choice and play it out of the sound card. If it goes silent, it runs a script called mailsend.pl. This is a shifty little script that we have to e-mail us when things go silent.
However, if the stream fails completely, we fall back to playing the emg.wav file on loop. Sounds good but it’s worth remembering that it will resume the backup file from wherever it stopped last on every subsequent failure. While that might sound odd to the ear, you don’t end up hearing “She Wolf” every three minutes when the ADSL line flaps.
*May not actually be Sony Award winning.
PS – I know there’s a phone number on the CODEC. However, it’s the public studio line so not that big of a deal. 😉
Hi,
thank you for this tuto !
but when i launch the script i have the message:
“char 12: the variable output.alsa used here has not been
previously defined”
a problem with this line: output.alsa(radio_stream)
I have a raspberry pi and i did exactly what you explained.
any suggestion ?
thanks
Have a look and see if the liquidsoap-plugin-alsa package is installed. If it’s not, apt-get install liquidsoap-plugin-alsa should get it in place. There’s also a liquidsoap-plugin-all package that should install every available plugin.
If it’s there and still doesn’t work, shout and I’ll have a go with a newer Pi installation to see if I can figure it out.
ok thank you !
i will try and i will tell you
Thank you so much
Would it be easy to tell the Pi to read the fallback MP3 file off a USB stick plugged into one of the USB ports?
Should be easy enough but you’d have to configure the USB stick to auto-mount. An appropriate entry in /etc/fstab combined with a new folder called /media/usb or similar would allow that to happen on boot.
At that point, it’s possible to change the backup file to point at a file on the USB stick.
Though, if you’re going down that route, you can get a lot more clever with LiquidSoap. For example, it’s possible to have it select from playlists of IDs and songs. See this page for some examples of what you can do with a bit of scripting.
I really like your posts. I’m wondering if you have ever tried to install Rivendell on a RaspPi2 yet? I’ve been trying but can’t seem to get past the configure stage when trying to compile it from source. Any insight?
I’ve not had a chance to do anything with the Pi2 yet. That said, I’ll be ordering one soon for various little projects.
As for getting Rivendell going, I’ve heard it’s possible but not had a shot myself. Something else impressive I’ve heard about is getting Stereo Tools going on a Pi2.
I’d be surprised if Rivendell isn’t possible on the Pi2 (ignoring any potential compile to ARM issues). We’re getting to the stage where these little boxes are more powerful than the old Pentium systems we used for all sorts of odd jobs in my student radio days.
As for your specific problem, what errors are you seeing on the configure stage? They’ll usually give a hint as to what’s not quite right.
I don’t have it running at the moment but it had errors about ccdb and finally Libparanoia not found. It seemed to be relating to CD drives which of course aren’t to be found on the Rpi2
Indeed. I’d be very impressed if someone could squeeze a CD player onto the Pi. 😉 That said, it may be possible to download and compile those separately for the Pi. Well, assuming they’ll port over to ARM fine.
If you’re lucky, it might be possible to install on the Pi using “apt-get install libcdio-paranoia-dev”. Otherwise, it’ll need that library compiled from source.
Love the sound of this project, we’re currently using the Barix instreamer/exstreamer setup, over a mile long wifi link, biggest downside of the Barix’ is the lack of a large enough buffer, the wifi link does suffer the occasional blip (or Flap as you rightfully put it!) and it’s just enough to interrupt the playback, so I’m hoping a pair of Pi B’s (one with a Wolfson audio board) can effectively stream AAC encoded audio over the link, with a large enough buffer to accommodate for the odd flap at the expense of a bit of latency, given the choice I’d rather have latency than drop-outs! Keep up the good and very informative work, I’ll let you know how I get on 🙂
Hi Marc
Have had some issues with this but getting there still a noob.
Where can I find script for Piface that you use and mailsend.pl.
Also everytime I boot the alsamixer volume has to be reset.
Do you find the Pi audio noisey?
Any help appreciated.
The mailsend.pl script was just mentioned as an example. That said, all it does is send an e-mail when it’s called. An example of how to do this on a Raspberry Pi can be found here.
As for the noise on the output, we’ve not really noticed it. That said, we’re pushing compressed audio through it at a reasonable level. However, it is possible to improve the audio output through the use of the Wolfson/Cirrus Audio board. It does require a bit of work to get going but should improve on any problems you may have.
Hi , is it possible to use this with a mobile net dongle (3 or 4G)
Could anyone make me an image on SD disk of software pre installed as my knowledge and time available is limited on this still.
Please reply to our email. Offer of a gesture of a few quid to show appreciation for your time
There’s no reason this couldn’t work over a 3G (or 4G) mobile service. So long as the Icecast server is publically available or you can setup a VPN connection, it should work. Though you are at the whim of the mobile network in terms of availability and I’d expect some contention problems if you’re in a high traffic area (e.g. near an arena during an event).
As for building an SD card image, I’m afraid I don’t have the time to build and test one. That said, installing the required software shouldn’t be too taxing if you can get a standard Raspbian image on an SD card for a Pi.
Nice one, Marc. Glad I found this post. Got the Raspian image on the SD card.
Hi,
I am trying to use this script to detect silence for our hospital radio, we are planning to recive our shoutcast stream via VLC, I have this working but we are looking to play a wav if the network or audio fails. I have followed your tutorial above but keep getting “line 4, char6 empty token” when running the program. do I need to define that somewhere?
Apologies my programming knowledge is very small.
If this is the stl.liq file we’re talking about, it’s probably the quote marks used on that line. Try removing those and typing them in again yourself. If that works, it was a character encoding issue from the copy and paste. Something that unfortunately people out quite regularly with code snippets.
Hi Marc,
thanks for that i am getting a parse error on line 29, any ideas
That’s the output.alsa one. If that’s not working, I’d check you’ve got the ALSA plugin for Liquidsoap installed. Otherwise, I can’t see anything obviously wrong with it.
Great post mac Got the Raspian image on the SD card.
Thanks
This is EXACTLY what we are looking for!!.. But what about on the sending end?.. I have 2 New Pi’s.. 32 Gig SD Cards.. and have not set anything up yet… We have 2 Frequencies at the Tower that are being Simulcast From the Studio.. We want to Split the Frequencies.. One for Music .. One for Talk Radio… So Idea is from Mixing Consoles.. Split Audio Output from Mixers going to existing STL.. then At Transmitter Site.. Original STL for Main Frequency and Secondary Pi STL For transmitter 2!.. What you have described sounds like Pi Receiver Audio could go straight to Transmitter 2 at Tower, but need to set up Pi Transmitter on Studio Side !! Can you Help?.. Thanks..DC
The modern Raspberry Pis should be able to encode in real time now. You could potentially use the same tools to do this. Have a look at the encoding part of the LiquidSoap documentaion. It should be able to point you this right way.
Otherwise, you’re looking at using Darkice (or similar) to encode. Both options will need Icecast installed on the TX end Pi.
Another option to look at would be OpenOB. It does a similar job but is purely point-to-point from what I remember.
Hi Mark, Great little project however had a few niggles with the script maybe because copy and paste kept getting “line 4, char6 empty token” i have sorted that now and now im getting That source is fallible, do you have working file or any advise on what is causing this thanks for any help
All the best
Chris
Here’s a tricky (possibly?) advanced feature I was wondering whether possible or not… If silence detected, try reloading the stream first once or twice – if audio present resume as per normal – if still silent then play backup wav.
I have found that with our school radio station shoutcast stream that sometimes the stream will pause on the listening device even though the stream itself is still running fine, a simple page reload will fix this and we would require an email notificatin unless hte station itself was silent for a long period due to the station being down.
ALSO, will the code auto-resume the stream once audio comes through again if the station audio had infact been offline?