This little post started because of halloween. Most of my friends know that throughout the years if I am going to dress up for halloween, I'm either a cop or a ninja. Almost every year. One year I was a soldier which is pretty much a cop in fatigues. And one year I wore an orange shirt that read "This is my costume". Halloween is right around the corner and I'm most likely going to be a cop again.
I've been getting more authentic by the year whilst hanging on to Arizona Revised Statute 13-2406. I thought it would be cool this year if I made cop noises. You know the crackle of a radio followed by a "10 baker adam 692 in progress 4000 block south 15th street, respond code 2" or something like that.
My brain started churning and remembered that you can get Tucson's police radio feed streamed to your computer! I figured if I could get my computer to record some good busy radio traffic, I could either (cheap way) play it on my phone, or (not so cheap way) build a walkie talkie amplifier from parts at the Good Will and play it from an mp3 player.
When I found the link to listen to Tucson's radio, I was given a playlist for Windows Media Player. But, inside that was an XML file that had the url from where to stream it. I logged into the server and wanted to see if I could stream it directly into a file:
$ sudo wget http://relay.broadcastify.com:80/745565660
With that command, it started streaming into a file called 745565660. At this point I didn't know if there was any audio on that file at all. I just knew it existed and wasn't zero. So I used file to get some more info about it:
$ file 745565660
745565660: MPEG ADTS, layer III, v2, 16 kbps, 22.05 kHz, Monaural
I learned that that format is an mp4, Audio Data Transfer Stream. Never heard of that before, but I know that I want it changed to a wav. avconv was already installed on my Crunchbang awesome linux machine so I actually wound up converting it to an mp3, and then a wav. I'm sure you can put it strait to a wav, but for the sake of putting exactly what I did:
$ sudo avconv -i 745565660 -c:a libmp3lame -ab 16k -y 745565660.mp3
$ sudo avconv -i 745565660.mp3 745565660.wav
Now the audio part is taken care of. Of course, you can use any wav file that you have. I knew that my linux probably needed some dependencies installed ahead of time, so for that, I followed the instructions at github that got everything in that I needed:
$ sudo apt-get install make g++ libsndfile1-dev libpng++-dev libpng12-dev libboost-program-options-dev
I noticed in my research that sndfile-tools is an insteresting little package for manipulating audio but didn't fit exactly what I needed. But I'll probably hit that in a little while now that the libraries are installed. I guess it's also good to note that I found a program called SoX that does a ton of things including making spectrograms of audio files. Here is the one that I made - it looks pretty cool, but not exactly what I was looking for:
Then I navigated to an area for developing stuff, downloaded a fresh copy of wav2png which automagically put it in a folder wav2png. For the sake of saying, when Crunchbang installs, you have a user automatically set up, so I have a folder there, /test that I use for my development stuff.
$ sudo git clone git//github.com/beschulz/wav2png
When that's all downloaded, I found the wav2png/build folder, cd'ed into it and then...
make
I'm still kind of new to compiling binaries and the proper way to do things and have been too busy/lazy to read up on it, so you may know better than I, but this will compile the program and put it in the folder wav2png/bin/Linux/wav2png. I don't know for sure if you use make install if that will install it into the /usr/bin of your system making it available through your $PATH, but at this point, I just used it where it landed and it works fine for me.
To make the image that you see at the top, I took my few minutes of radio chatter and ran it into the machine. This had to be run from the directory the binary was created in:
$ sudo ./wav2png --background-color=ddddddaa --foreground-color=003168ff -o /var/www/test/wav2png2.png ~/test/745565660.wav
And presto it was done. It outputted out a lot of separated percentages to show it's progress as if it were supposed to overwrite in one place, but I don't mind - it worked.
What does this have to do with halloween costume? Well, not really much. My first thought was that there wasn't going to be all that much chatter and I can see what's on the whole thing visually, but as you can see there is quite a bit. But when I couldn't get it working, it became a quest and I had to get it working. I could imagine that I can use this to visually map out my original music for some cool thumbnails, create actual waveforms for some cop/techie crime video project (that gives me an idea!), or more practically, I can take my 10 years of saved stock music and sound effects and have a visual aid to find the one I'm looking for instead of listening to all of them - again!
Hope that helps! Visit crunchbang if you're looking for the best linux distro eva!