
Automatic check for unbalanced audio, or bad level
I have a radio show and I’m also one of the people much involved in all the tech-related stuff in the Radio. There are multiple system that automatically, and manually, record the podcast of a show, upload it online and similar stuff.
Sometimes the recorded podcasts have some problems, typically:
- The audio of the left channel is unbalanced with the respect of the right channel, or viceversa (Unbalanced volume level)
- The audio is too high
- The audio is too low
It may happen because the analogic audio system, before the audio card sampler, was misconfigured, or someone move some knobs, or maybe the cable are too long and of bad quality. Anyway, when this happen, there is no way I can understand it other than listen to all the recorded files.
We are around 40 speakers, we broadcast liver from 8:00 to 24:00… it’s not something that a human want (and can) do. So for this type of problem computer systems is the way. I need
something that automatically can understand if a file is unbalanced, too high or too low in volume
I think that Linux is a super operating system and it’s full of library, tool, script and community that can help you find the right solution, but sometimes it’s not so simple. The siwss-knife I was looking for is called sox. Sox is a command line tool that can do tons of stuff (see here for the documentation). What I used for this is the stats option
sox FILE_NAME.mp3 -n stats
stats
returns a lot of info, and what I was looking at was the RMS db level, global and for each channel (left right). To filter out these result we can use a simple grep
command:
sox FILE_NAME.mp3 -n stats | grep 'RMS lev dB'
And with some ‘magic’ get the numeric info about TOTAL level, LEFT and RIGHT level:
LINE=$(sox FILE_NAME.mp3 -n stats | grep 'RMS lev dB') TOTAL=$(echo $LINE | tr -s ' ' | cut -d ' ' -f 4) LEFT=$(echo $LINE | tr -s ' ' | cut -d ' ' -f 5) RIGHT=$(echo $LINE | tr -s ' ' | cut -d ' ' -f 6) BAL_DIFF=$(echo "($LEFT)-($RIGHT)" | bc)
What we have done here? Saved the output of the sox command to the variable LINE:
LINE=$(sox FILE_NAME.mp3 -n stats | grep 'RMS lev dB')
and then we’ve parsed it 3 times:
TOTAL=$(echo $LINE | tr -s ' ' | cut -d ' ' -f 4) LEFT=$(echo $LINE | tr -s ' ' | cut -d ' ' -f 5) RIGHT=$(echo $LINE | tr -s ' ' | cut -d ' ' -f 6)
and stored the LEFT/RIGHT difference to a variable BAL_DIFF
BAL_DIFF=$(echo "($LEFT)-($RIGHT)" | bc)
from now on what you need to do with these value is up to you, you can check if values are less then a threshold and send an email, store the value somewhere, push an alert.

How to listen http webradio stream in an https site (Chrome > 80)
Since October 3, 2019 Chrome is gradually rolling out the new security feature that will block mixed content in the websites (info here). So that, if you have a webradio site in https and your streaming is in http, then none will listen to your webradio stream in your site. This is gradually happening at the beginning of 2020. There are multiple solutions, obviously the easiest and the smarter one is to move your streaming to an https connection.
To do so you can ask your streaming provider to move/modify your server to a secure one.
But this could take times, could be expansive or impossible (if your streaming provider service do not have this option). A good solution is to proxy the stream using a php script hosted in your website. So suppose you have a website at the address
https://www.myradiowebsite.com
And suppose your stream is at
http://mystreamprovider.mywebradio.com:someport/streamendpoint
Let’s create a file, let’s call it stream.php and let’s wrote in it:
<php?
$filename = "http://mystreamprovider.mywebradio.com:someport/streamendpoint";
header("Content-Type: audio/mpeg");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$filename);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
echo $data;
return strlen($data);
});
curl_exec($ch);
curl_close($ch);
With the usage of the curl function in php, basically we are proxying the non-secure connection to the stream with the secure connection of your website. And we’ve also removed the cross-site problem (side effect: we’ve also hidden your streaming provider info, so that, none will know who is hosting your streaming service and can’t know the number of your listeners…). All you have to do now, is to modify in your website, all the references to the original stream so search/replace or configure your website according to this substitution
find http://mystreamprovider.mywebradio.com:someport/streamendpoint
and replace with https://www.myradiowebsite.com/stream.php

Katzenjammer del 14 gennaio 2018
Podcast: Play in new window | Download
Subscribe: Apple Podcasts | RSS
Il blackout alla più grande fiera tecnologica del mondo, i lanci segretissimi di space X, le novità discografiche e i ricordi musicali con le celebrazioni di date importanti. Tutto questo è stato Katzenjammer del 14 gennaio 2018.
- I Don’t Wanna Stop – Good Charlotte
- Water Slide – Wooly Mammoths
- Girlfriend – Kaufman
- Catch You Dreaming – Ride
- Lotto In Reverse – Alex Lahey
- Life On Mars? – David Bowie
- La Bomba In Testa – Fabrizio De André
- Turtle Neck – Bosnian Rainbows
- All Nerve – The Breeders
- Animali – Cosmo
- Il caffè del teatro – La municipàl
- Annabelle – Fast Animals and Slow Kids
- Wicked – Cycle
- Don’t Kiss Me Goodbye – Ultra Orange Emmanuelle
- Smells Like Teen Spirit – Radio Edit – Patti Smith
- This Mess We’re In – PJ Harvey
- Typical Situation – Dave Matthews Band
- Mao – Bolla di sapone
- Parklife – Blur
- Let Go – Frou Frou

Katzenjammer podcast del 8 ottobre 2017
Podcast: Play in new window | Download
Subscribe: Apple Podcasts | RSS
Onde gravitazionali, radio e del mare. Foto di Jedi in libri di scuola, riconoscimento facciale. Musica dalla Spagna, dall’Italia, dalla Francia (come una barzelletta con protagonista un fantasma formagino…) e ospiti casuali. Questo è stato Katzenjammer di Domenica 8 ottobre 2017.
- (Feeling Like A) Demon Again – Primal Scream
- The Culling – Chelsea Wolfe
- Sinnerman – Nina Simone
- Never Wanna Know – MØ
- Metti una sera a cena – La band del Brasiliano
- Le Villejuif Underground – Le Villejuif Underground
- Radioactivity – Damien Jurado Richard Swift
- Mina – Verdena
- Giorni – Diaframma
- La taberna del Buda – Café Quijano
- Tu Puto Grupo – Los Punsetes
- California Dreamin’ – The Mamas & The Papas
- Radical Eyes – Prophets Of Rage
- Vecchie dogane – La Municipàl
- Lessons In Love – Level 42
- The Violence – Rise Against
- Walk On Water – Thirty Seconds To Mars
- Senza Vento – Timoria
- Susan’s House – Eels