| Getting Started with Linux - Lesson 18 |
|---|
Now that we have our sound card working, it's time to check out
some of the options that we have for playing sound. If you're following the
course in order of the lessons, we haven't begun to talk in depth about the
use of the X-window system in Linux, so the tools for playing and recording
sound here will be used from the command line.
I'd also like to add an editorial comment, if I may. I use a window manager
but the programs I listen to CDs, MP3s etc. are command line
applications. I am not implying that there aren't some fine programs for playing
and recording sound. There certainly is some nice stuff out there. The programs I use
(which we'll talk about here) are great applications that work just as well as their
graphic counterparts but in many ways are more easily configurable, at least
for me. Besides, we're talking about sound, so I just have to set the CD or
playlist and listen. I really don't have to see anything.
Recording Sound
Due to Microsoft's monopoly on operating systems (yes, they have been convicted
of this in a court of law), the most popular format for sound recording is is
their *.wav format. When you make a recording of yourself or
someone else speaking or you "rip" a track from a CD for later conversion to
mp3 or ogg (we'll talk about this new and open format later), you're probably
going to use the *.wav format. If you simply want to record yourself saying
something using Linux, all you need is a microphone and and recording tool that
gives you a file in this format. For this lesson, we'll use 'wavrec'.
'wavrec' is easy to use. It's easy because the default recording settings for
this applications are all acceptable for getting a quality recording (if you've
got a fairly good microphone). You just have to type some simple commands and you're all set.
Here's an example:
Let's say I want to record a note to myself that says the following: "Note to
self: make sure you respond to Dave's email about SuSE'. I would just type the following"
wavrec dave_note.wav
make sure the microphone is on (you'd be surprised how many times I forget to
turn it on!) and start talking. The default recording time for 'wavrec' is 10 seconds. That
means, if you don't specify a recording time on the command line (I didn't)
you'll get a 10 second long sound file. My sentence above, "Note to self .....
bla bla bla" lasts about 8 seconds. Of course, the duration of the sound file
depends on whether you're talking a normal rate. If you auction cattle in Iowa,
then you probably don't need 10 seconds to say that sentence, so you should modify the
time for the file, like this:
wavrec -t 3 dave_note.wav
The -t option refers to seconds, so you should type the number of seconds
after. Here, even 3 seconds might be pushing it for a cattle auctioneer. Just
remember to give yourself enough time for what you want to say, in seconds. If
you want to recite Abraham Lincoln's Gettysburg Address, then you would first
multiply 60 and 2 to get 120 seconds. Why this figure? Because Lincoln is
reported to have taken only 2 minutes to give this famous speech. If you would like
to record Cuban leader Fidel Castro's speeches, then I would advise getting a
huge hard drive. He once made a speech that lasted 7 hours.
You can add all kinds of options to wavrec. I use this tool all the time to
record short sentences for use in computer assisted language learning. Here are
the values I use:
wavrec -S -t 5 -s 44100 a_sentence.wav
Let's explain these options. The first one, -S, means stereo. If
you look at the man page for 'wavrec' (type: man wavrec), it says that stereo is the default.
Nevertheless, I have noticed that mono is in fact the default. That is to say,
if you use 'wavrec' with no options, you get mono not stereo sound. It would
seem there is an error in the man page. After the
-S, we have the -t option for seconds (we explained before) then we have the -s
option which is the sampling rate in Hz. I chose 44100 because this is a good
high-quality sound which is necessary for my language teaching endeavors. It's
important not to confuse the -S (capital letter) with the -s (lower case). -s
takes a value in Hz while -S has no value. I have purposely put the -t option
in between them to avoid confusion. There you have it. Issuing this short command
and then changing the file name, I get a lot of work done because my sentences
seldom last more than 5 seconds and these values are fine for my work.
Now, you must be asking the question: "I've made a *.wav file, now, how do I hear it?"
The answer is easy: With 'wavrec' 's companion program, 'wavplay'. Here's how:
wavplay a_sentence.wav
This will play the sentence we recorded above. That's all there is to it. I
should also point out that the same options in 'wavrec' are available for
'wavplay' if you want to add some effects to playback. For example, if you take
our first wav file, dave_notes.wav, and play it like this:
wavplay -s 44100 dave_notes.wav
you'll find it's doubly fast. That's because our note about Dave was recorded
at the default 22050 hz, so if you do the math, you see that what we've done is
double it's sample rate . You might want to do this:
wavplay my_favorite_song.wav
then sing a line of your favorite song. Play it back to your friends using the
-s 44100 option and have them rolling on the floor with your Alvin and the
Chipmunks impressions. I have actually entertained my 2 year old son for hours with this.
Using the same logic, if you take our a_sentence.wav and play it like this:
wavplay -s 22050 a_sentence.wav
you've cut the sample rate in half and so you get a really cool impression of
the creatures that take over people's bodies in Star Trek's original series
episode 'The Lights of Zetar'.
I know what you're probably thinking. I need to be productive. I don't want to
record Chipmunk sounds and sci-fi weirdness. Well, then. Here's a good way to
use these tools, plus a couple of other command line tools to read reminders to
yourself in the morning, or whenever you'd like.
First, create a subdirectory in your own directory /home/[you]/
mkdir reminders
then go into reminders (type: cd reminders). Now, Let's create a sort of
introductory wav file that's always going to be there. I'll explain why we need that in a bit.
wavrec -t 3 0intro.wav
Say something like "Your reminders" or "Reminders for you". Three seconds
should be enough for that. You may have noticed that the name begins with
zero. That is simple because for our reminder system, we invoke 'wavplay *'
with the asterisk to play every file in that directory. By naming it
'0intro.wav', that assures that it will be played first with our system.
Now record some reminders. I recommend using a YEAR-MONTH-DAY format plus some
meaningful word for naming the wav files. For example, type:
wavrec -t 5 2001-10-24_trash.wav
and say: "Remember to take out the trash". I suppose 5 seconds should be enough
to say this. Try recording a few more reminders for different things, like
"call cousin Jack" and "remember to pay back gambling debts to bookie".
When you've got a few wav files in there you should play them to see
that they've come out all right (you don't need to do this every time - we're just practicing)
wavplay *
You'll see that the 0intro.wav file gets played first. If everything sounds
good to you, then we're ready for the next step which is to play our files
automatically at a given hour.
One of my favorite applications in Linux is called 'cron'. This is a pretty
powerful tool that is used primarily by system administrators to automate their tasks and
duties. It's powerful because it can schedule something to be run automatically
at any time, whether that be once every three minutes, every hour, once a day
or every Thursday. It can even be used to run a job that you do only in
January. But just because it's powerful, it doesn't mean it's complicated to
use. For our purposes, it's very simple to configure 'cron' to play our
reminders. First, we have to edit a file that is called 'crontab' and add our
instructions. There is a system-wide crontab file for root's exclusive use, but
there is also one available to every user to run command line apps that he or
she is authorized to use. To add a job to be done, just type:
crontab -e
Then we add the following line to our crontab file (-e is for edit)
30 7 * * * /usr/X11R6/bin/wavplay $HOME/reminders/*.wav
The crontab edit procedure uses your default command line editor which is
probably 'vi', so if you don't remember our little tour of 'vi', just press
'ESC + i' before you add this line.
Let's explain how a crontab file works. The file is read by the program 'cron'
and it carries out the instructions in it. In our example, our wav files get
played at the 30th minute of the 7th hour, that is to say 7:30 in the morning.
This is because the crontab file must start with the minute [0-59] you want
something done, followed by the hour [0-23] the day of the month [1-31], the
month of the year [1-12] and the day of the week [0-7] (where 0 and 7 are both
Sunday). I have left the last three as asterisk. This tells 'cron' that these
values don't matter. That is to say, cron should play our *.wav files every day
of the month, every month of the year, 7 days a week.
The next step as you can see is to tell cron to run 'wavplay' and play the
files in your home directory. We use the symbol $HOME for that.
Also notice how I have put the exact path to where wavplay is. To
see if your system differs, then type:
which wavplay
to show you where the program is. Then adjust accordingly. I used this exact
path because, it would seem on my system, the master crontab file (found in
/etc/crontab ) doesn't recognize that path automatically. I am assuming that
this is for security reasons, so I didn't go in and change the path. Some
things are probably best left alone, so no harm done if you just put in the
exact path in the crontab file.
If you want to test it, just give it a time within a couple of minutes or
so. That is, if it's 3:30 in the afternoon, you might want to first edit your
crontab like this:
32 15 * * * /usr/X11R6/bin/wavplay $HOME/reminders/*.wav
that will play the reminders at 3:32 PM, to show you that it works. Just make
sure you're not playing anything else, like MP3s, because you won't hear
them. That's the rationale for my 7:30 AM start time. It's a good hour for me -
when I am just getting to work and I'm probably not listening to heavy metal at
that hour of the morning. Actually, I never listen to heavy metal.
Now, when you've finished hearing them, you can delete them (if you want)
That's where the rationale behind the YEAR-MONTH-DAY.wav comes in. You just
delete the daily ones by typing, for example
rm 2001-09-28*
That keeps the 0intro.wav file in there. I mentioned before that I was
going to explain why it's necessary to have it there. 'Cron' will mail you when
there is an error, so if you had no reminders for a given day, you would at
least have one file in the /reminders directory. That way, 'cron' doesn't have
to mail you an error message because the program 'wavplay' didn't find any *.wav files.
By deleting the unnecessary reminders, you've got some free disk space. Speaking of that,
if free disk space is something that worries you, in the next part of the
lesson we'll talk about those famous (and controversial) files that take up
less space - MP3s - and how to make them under Linux. We'll also talk about the
new free audio format comparable in sound and space to MP3 - Ogg Vorbis.
[Previous] [Next]
|