LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Script for auto-audio-recording - Crontab (https://www.linuxquestions.org/questions/linux-general-1/script-for-auto-audio-recording-crontab-378278/)

ctkroeker 10-30-2005 05:41 AM

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?

maroonbaboon 10-30-2005 07:23 AM

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.

ciotog 10-30-2005 10:59 AM

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
sudo nice --10 arecord -D ameter -f cd a.wav
sudo chown ciotog:users a.wav


maroonbaboon 10-30-2005 04:15 PM

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.

ciotog 10-31-2005 12:07 AM

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

linmix 11-01-2005 02:57 AM

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.

maroonbaboon 11-01-2005 04:53 AM

+%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).

linmix 11-01-2005 08:58 AM

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)

ciotog 11-01-2005 11:03 AM

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.

linmix 11-01-2005 11:36 AM

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.

ctkroeker 11-23-2006 06:37 AM

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?

ctkroeker 11-23-2006 11:14 AM

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
and the next one would be
Code:

11-23-06_1600.wav
and so on.
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.

Tinkster 11-23-2006 11:29 AM

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

ciotog 11-23-2006 11:43 AM

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 &
The important parts are the second parameter */2 which says to run it every 2 hours (on the even hours), and the ampersand which says to run it in the background (or else it might not start a new recording if the previous one hasn't quite finished yet and the soundcard is locked).

To be honest I've never really set up a crontab entry like this before, so caveat emptor.

ctkroeker 11-23-2006 12:42 PM

Quote:

Originally Posted by ciotog
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 &
The important parts are the second parameter */2 which says to run it every 2 hours (on the even hours), and the ampersand which says to run it in the background (or else it might not start a new recording if the previous one hasn't quite finished yet and the soundcard is locked).

To be honest I've never really set up a crontab entry like this before, so caveat emptor.

Thanks, I'll try that. Makes sense. I saw something like this on another site, but it was different. This makes sense.


All times are GMT -5. The time now is 01:02 PM.