VOX Recording in Linux (part 2)

After I made my last post about how to do line-in recordings from your scanner radio with silence detection and cutting, also known as VOX recording in the old days, I started looking at SoX the Linux Sound eXchange CLI audio processing application. Using SoX is a lot slicker than my arecord-mp3splt-mpgjoin method. It lets you do the recording, silence detection, and mp3 encoding in one line, and it puts everything into one audio file, no muss no fuss.

Here are some examples:

rec -r 44100 -p | sox -p OUTPUT.mp3 silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d

rec -r 22050 -c 1 -p | sox -p OUTPUT.mp3 silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d

The first one will give you a 44.1 kHz, stereo, 128 kbps MP3. The second one will give you a 22.05 kHz, mono, 32 kbps MP3.

The rec command does the recording, -r specifies the sampling rate and -c sets the amount of audio channels, “-p” means the input is piped to another command. The sox pipe also needs a “-p” to tell it that its input is coming from a pipe, in this case the rec command.

The crypt CLI switches in the piped sox command “silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d” is what does the silence detection and trimming. It means to cut silence from the beginning of the file and parts within the middle and end. “xx:xx:xx.x” is in hh:mm:ss.s format and tells sox the minimum duration to consider valid audio. In my examples I have this set to 0.5 seconds for valid audio. The “-45d” means -45dB and is the minimum valid audio level to do trimming. In other words, if you were to say -100d, basically everything would be considered valid and there would be no trimming, you will need to play with this depending on your input levels.

I made a test for almost 2 hours with my scanner connected and scanning the aircraft bands. I ended up with a 22 minute file. Very nice!! Now I’d say we have a very nice Linux-style “scanner recorder” program, and it’s a hell of a lot slicker than anything you’d find in Windows.

If you are a Debian or Ubuntu user, you will need to compile your own version of SoX if you want to encode to MP3. This bug explains that the version of SoX in the Debian repos was compiled without MP3 support. Anyway, all you need to do is download the latest source, make sure you have all the build deps (apt-get build-dep sox), make sure you have the libmp3lame and libmp3lame-dev packages installed, then just do ./configure, make, make install.

When you do the ./configure you’ll see a list at the end of the output of what capabilities will be compiled into sox, just make sure that it says you will have MP3 support. Your compiled version will go into /usr/local by default, so you don’t need to uninstall the repo version of sox, since that one is in /usr and programs in /usr/local always take precedance. You can verify that by doing “which sox” after installing it and it should show you “/usr/local/bin/sox”.

About these ads
This entry was posted in Audio and tagged , , , , , , , , , , . Bookmark the permalink.

7 Responses to VOX Recording in Linux (part 2)

  1. Nick says:

    Btw – you can combine rec and sox into one command: eg:
    sox -t alsa default -r 44100 output.wav silence -l 1 00:00:00.5 -25d -1 00:00:00.5 -25d

  2. Mahmudul Hasan says:

    Simply great ! I am using it right now !

  3. Gerhard says:

    Cool stuff! I searched for a tool to do that. Using good old sox is a pleasure.
    Thanks.

    Gerhard

  4. Jeramy says:

    This is my first time pay a quick visit at here and i am truly impressed to read everthing at one place.

  5. Joni says:

    Hey! This post could not be written any better! Reading this post reminds me of
    my old room mate! He always kept chatting about this. I will forward this
    write-up to him. Fairly certain he will have a good read. Many thanks for sharing!

  6. Thanks for finally writing about >VOX Recording in Linux
    (part 2) | mochaRHW Linux Blog <Liked it!

  7. Brigida says:

    Thank you, I have recently been searching for information about this subject for a while and yours is the greatest
    I’ve found out till now. But, what in regards to the conclusion? Are you sure in regards to the supply?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s