LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-30-2005, 05:41 AM   #1
ctkroeker
Senior Member
 
Registered: May 2005
Location: Paraguay
Posts: 1,565
Blog Entries: 1

Rep: Reputation: 50
Question 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?
 
Old 10-30-2005, 07:23 AM   #2
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
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.
 
Old 10-30-2005, 10:59 AM   #3
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 727
Blog Entries: 2

Rep: Reputation: 43
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
 
Old 10-30-2005, 04:15 PM   #4
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
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.
 
Old 10-31-2005, 12:07 AM   #5
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 727
Blog Entries: 2

Rep: Reputation: 43
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

Last edited by ciotog; 10-31-2005 at 12:09 AM.
 
Old 11-01-2005, 02:57 AM   #6
linmix
Senior Member
 
Registered: Jun 2004
Location: Spain
Distribution: FC5
Posts: 1,993
Blog Entries: 1

Rep: Reputation: 46
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.
 
Old 11-01-2005, 04:53 AM   #7
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
+%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).
 
Old 11-01-2005, 08:58 AM   #8
linmix
Senior Member
 
Registered: Jun 2004
Location: Spain
Distribution: FC5
Posts: 1,993
Blog Entries: 1

Rep: Reputation: 46
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)
 
Old 11-01-2005, 11:03 AM   #9
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 727
Blog Entries: 2

Rep: Reputation: 43
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.
 
Old 11-01-2005, 11:36 AM   #10
linmix
Senior Member
 
Registered: Jun 2004
Location: Spain
Distribution: FC5
Posts: 1,993
Blog Entries: 1

Rep: Reputation: 46
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.
 
Old 11-23-2006, 06:37 AM   #11
ctkroeker
Senior Member
 
Registered: May 2005
Location: Paraguay
Posts: 1,565
Blog Entries: 1

Original Poster
Rep: Reputation: 50
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?

Last edited by ctkroeker; 11-23-2006 at 10:49 AM.
 
Old 11-23-2006, 11:14 AM   #12
ctkroeker
Senior Member
 
Registered: May 2005
Location: Paraguay
Posts: 1,565
Blog Entries: 1

Original Poster
Rep: Reputation: 50
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.
 
Old 11-23-2006, 11:29 AM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
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
 
Old 11-23-2006, 11:43 AM   #14
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 727
Blog Entries: 2

Rep: Reputation: 43
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.
 
Old 11-23-2006, 12:42 PM   #15
ctkroeker
Senior Member
 
Registered: May 2005
Location: Paraguay
Posts: 1,565
Blog Entries: 1

Original Poster
Rep: Reputation: 50
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.
 
  


Reply

Tags
cronjobs, recording


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Audio Recording. svendabassist Linux - Software 1 02-03-2005 11:08 PM
Recording Audio-in Dirk the Daring Linux - General 0 12-23-2004 10:43 AM
auto-completion - how does it work & can my script args auto-complete? BrianK Programming 1 06-11-2004 04:51 PM
need help recording audio havokok Linux - Software 0 03-03-2004 07:41 PM
Recording audio with linux karim Linux - Software 0 10-06-2003 07:40 AM


All times are GMT -5. The time now is 12:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration