Script for auto-audio-recording...
How would I make a script that would record audio at specific hours and bit-ratess (ie: 2:00-3:00, 3:00-4:00, and so on)? And then save it as mp3?
|
1. First capture the audio (http://www.tldp.org/HOWTO/Sound-HOWTO/)
2. Pipe it into the 'lame' encoder (see man page for lame) to get mp3 format, 3. Wrap it up with 'timeout' (see man page for timeout) to set recording period, 4. Make it all into a shell script and enter it in 'crontab' (see man page for crontab) to run at scheduled times. Instead of crontab you can also use 'at' (see man page for at). Sorry that's not exactly a script. Maybe someone else has something closer to a final product. |
I have a short script that I use to record vinyl albums for further processing with gwc. In order to nice the recording I have to run it as root so I added an entry to sudoers (and another to change ownership). Here's the script, you can build on it:
Code:
#!/bin/sh |
I guess the Sound HOWTO is a bit out of date, and 'arecord' is the right thing if you are using ALSA. I see it also has a duration switch (so 'timeout' not needed) and can write to standard output (as -). So I guess the basic recording command could be something like
arecord <some options> --duration 60 - | lame <some options> - outfile.mp3 except the name of the output file would have to change to stop overwriting. I don't understand sound recording with ALSA, so I have no idea what options would be needed in this case. |
The "-f cd" option sets it as 16 bit little endian, 44100, stereo, and that's really all you need. The crontab command could be:
Code:
arecord -f cd -d 3600 | lame -h - ~/recordings/$(date +%F--%H-%M).mp3 |
How would crontab know to place the original recording in ~/recordings ? Looks like F, H and M are assigned variables. are they lame specific, cron specific or can they be use systemwide without setting them first and getting ... well, what output, really? I'm interested in the script and at the same time trying to learn something about scripting etc.
|
+%F--%H-%M is a format argument to the 'date' command (see the date man page).
The notation $(command) is called command substitution. The shell replaces 'command' by its output (see Command Substitution in the bash man page). |
I read something about command substitution , but so far I'd only seen it after a variable had been set, like
read mn echo $mn Now I understand the variable you're calling is date which actually is a program which has a number of possible parametres. Thanks for the explanation. (Still so much to learn) |
To see what the date string would look like, try running the command in the brackets - you could tailor it as you like of course.
cron would simply run the command, in this case it's the lame program that puts the output in ~/recordings as specified. If you set up the crontab for your user acount then it would run the commands as you, so it will use your home directory. |
OK. Probably didn't read the command carefully enough. You pipe the input straight to lame - so lame doesn't read from a file in ~/recordings, but only places its output there. Think I'm beginning to understand.
|
Bringing up the subject again after a long time. I need to make crontab start a new recording every 2 hours of every day of every month of every year. But each time a file is done it's supposed to save the recorded file with it's date and time: i.e. 06-11-23-00-02.wav
How would I do this? |
Cronjob every two hours
I need to make cronjob start a new recording every 2 hours of every day of every month of every year. But each time a file is done it's supposed to save the recorded file with it's date and time: i.e.
Code:
11-23-06_1400.wav Code:
11-23-06_1600.wav How would I do this? I'm guessing I'll need a script for this, or a couple of them. But I'm not very proficient yet in writing them. So you'll have to help me. |
The hard part would be to stop the previous recording and make it save
the file with a given name. And the names suck, you can't sort those chronologically, you should have YYYY-MM-DD-time.wav, not MM-DD-YYYY (which is the most stupid convention anyone ever dreamt up :}). Which software are you using for recording, anyway? Cheers, Tink |
I think the best thing to do would be to check out the man page for crontab, as it instructs you on how to set up the crontab entry. Assuming that Ubuntu uses the same cron Slackware, the entry would be something like:
Code:
0 */2 * * * arecord -f cd -d 7200 /home/share/recordings/$(date +%y-%m-%d-%k-%M).wav 1> /dev/null & To be honest I've never really set up a crontab entry like this before, so caveat emptor. |
Quote:
|
All times are GMT -5. The time now is 01:02 PM. |