Automatically
Record Audio With Linux
This is a procedure that uses a shell script to automate audio recording using free and open source programs on a Linux computer. This can be very useful to automatically record radio station ID periods for late night DX'ing or to capture a favorite radio program for future playback. The Linux operating system cron scheduler is used to start unattended recording sessions. It will start at the times scheduled by cron and will run for the length of time programmed into the shell script. Note that some knowledge of Linux file editing, shell scripting and cron jobs is helpful when using this procedure.
This procedure uses the Linux program arecord, which is the command-line sound file recorder component of the ALSA sound card utilities to create .wav audio files. My system runs Ubuntu 10.04 and arecord was found pre-installed. To see if arecord is installed on your system, issue the command "alsamixer" at a command prompt. You should see the following window open. If it is not installed, use your system's package installer to add the ALSA sound card utility files.
The image above is the AlsaMixer playback control panel. To navigate, use the left - right arrow keys to select the desired level control, then use the up-down arrow keys to adjust the audio levels.
For recording, you will need to check the capture control panel. Use the F4 key to switch to the capture control panel view, shown below:
In the capture
control panel, navigate between the channels with
the left - right arrow keys. Use the space bar to activate the
control which causes the red "CAPTURE" to appear
immediately below the level indicator which confirms that this input
channel is turned on. Use the up-down arrow keys to adjust the
audio level. The escape key will close the control panel.
Probably you will have to feed audio into the sound card from your radio receiver to determine the correct level settings experimentally. If you are using the speaker output of your radio, low audio gain will be needed in the sound card. If the radio has a "record" output, greater gain will be needed in the sound card. After you have the shell script installed, make several test runs and set the radio volume and sound card level adjustments for the best quality recorded sound.
For the shell script, the first step is to create a new directory in your user home directory to hold the script and captured audio files. For example I'll use /home/username/radio where "username" is the your user name on the system. Also, create a new sub-directory inside the radio directory to hold the recorded files. For this, I'll use /home/username/radio/recordings
The next step is to create the shell script and place it into the /home/username/radio directory. Copy the following text, paste into your text editor (gedit) and save the file with the file name "record.sh".
#!/bin/sh |
Edit to set your desired recording duration and save the file in the /home/username/radio directory. Open a terminal (command prompt) and change directory to the /home/username/radio directory and mark it executable with the command:
|
chmod a+x record.sh |
|
1240 |
The script can be tested in a terminal (command prompt) by changing directory to the /home/username/radio
directory and issuing the command ./record.sh (you can also use
the command "bash record.sh"). The script should run and create a
.wav file in the /home/username/radio/recordings directory. It will run for the duration programmed in the script. You can prematurely stop the script by pressing the control and c keys (ctrl-c) at the same time.
The computer's cron utility is used to start the shell script at the desired times. A sample cron file entry is shown below that will start recording at 59 minutes after the hour during the hours of darkness every night (6 PM to 6 AM). Note that the term "bash" has been used in this example before the script name to allow the script will run even if it is not correctly marked executable. This is handy for testing purposes. Also, the script output is sent to the record.log file to create a log of every operation. Again, this is handy for testing and debugging.
|
59 18-23 * * * bash /${HOME}/radio/record.sh >>
/${HOME}/radio/record.log |
Edit this file for your desired schedule. You may create as many recording runs as you require. Save this file with the file name of "radiocron" in the /home/username/radio directory. To create the cron job from a command prompt, change to the radio directory, and enter the command "crontab radiocron". To see if the cron job was saved, enter the command "crontab -l" (that's the lower case letter "L" afrer the minus sign). Info on Cron is available at: http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
After the script runs, look in the /home/username/radio/recordings directory for the .wav audio recordings. They will have filenames similar to: 101103-1859-1240KHz.wav 101103 is the date (10th year as in 2010, 11th month, 3rd day. 1859 is the recording start time in 24 hour time based on the computer's internal clock. 1240KHz is the radio frequency (based on what you saved in the frequency.txt file).
The log file
is written when the script executes as a cron job. To view, open
the /home/username/radio/record.log file to see the log
information. Note that the log data
accumulates on every cron job run and can be manually deleted after it
is no longer
relevant. If logging is not required, simply remove ">> /${HOME}/radio/record.log" from the radiocron file and resave the cron job.
Hope this is beneficial to your radio listening. 73 and good DX'ing!
Page created
November 3, 2010 - Updated July 25, 2011