Trim off the junk
Before taking a recent long car trip, I started lining up CDs to
prepare for it when I realized how much better it would be if I could
take only the songs I liked. I could rip the ones I liked and then
burn them to a couple of CDs. It would save me from having to bring 20
CDs along and it would also serve forever after as a sort of 'greatest
hits'. One of the CDs I had was the Apollo 13 soundtrack which I had
bought shortly after seeing the movie. I noticed though that some of
the instrumental tracks had some lines of dialog from the movie at
the beginning. I had some time on my hands, so I wanted to see if I
could strip them out. Not that I don't like the line where Ed Harris
says: 'Failure isn't an option!', and of course, who can resist the
ultra-famous 'Houston, we have a problem.' - but my need to mess
around with things outweighs my need to be inspired through dramatic
dialog. So, I rolled up my sleeves and got to work.
Anyway, for whatever reason, let's say you want to remove parts of a
sound file. First, you'll need to find out how long the track is. The
following command will do this:
This will give you output similar to this:
Samples read: 63610880
Length (seconds): 721.211791
Scaled by: 2147483647.0
Maximum amplitude: 0.561218
Minimum amplitude: -0.631927
Midline amplitude: -0.035355
Mean norm: 0.072139
Mean amplitude: -0.000003
RMS amplitude: 0.095650
Maximum delta: 0.570465
Minimum delta: 0.000000
Mean delta: 0.045318
RMS delta: 0.064011
Rough frequency: 4697
Volume adjustment: 1.582 |
The only thing we need to be concerned about here is the length. As you can
see, the sound file in the example is 721 seconds long. Now, let's assume that
the first couple of seconds of this file is junk - something you want to cut out.
Seeing that we don't know the exact number of seconds of junk, we can play around
with it and see how much is junk. For this, we'll use the 'trim' option
in SoX. First, we can take a 'clip' from the file.
sox song.wav test.wav trim 0 10 |
Here we've gotten a clip of the first 10 seconds of the file. This is how it
works: sox fileyouhave.wav newfile.wav trim [SECOND TO START] [SECONDS DURATION]. It's
very important to point out that the second value is not a
place in the file, but the length of the 'clip'. I point this out because
my example, seeing that it's from the start of the file, is somewhat misleading.
For example, if I wanted to create a clip from 50 seconds into the file to
60 seconds into the file (another 10 second clip) the value wouldn't be
trim 50 60 but trim 50 10.
You can be also be very precise. You can use decimal points if you'd like
(trim 1.2 9.8, for example).
Now, let's say we've narrowed down the junk that we want to remove. The
first 7 seconds are junk and the rest is the soundtrack music we like.
Now, we'd create the file we want:
sox song.wav newsong.wav trim 7 714 |
As you can see, the original length was 721 seconds, so we need to
subtract 7 seconds from it. If you're going to the end of the song,
than it isn't all that important if you over shoot it, but don't
take too much off of it. If you also have junk at the end
of the song, then you'll need to be precise with your calculations.