Sorry for this basic question, but is there a simple way to use the
trim function in Sox to remove a specified amount of time off the
*end* of a WAV file?
Let's say 2 seconds, for example.
Is it necessary to know exactly how far into the file you want to
start trimming, or is there a way to just plug in 2 seconds as a
parameter?
I have read the documentation, but I found it a bit confusing.
Thanks!
Jonathan
sox infile outfile trim 0 0:0:2
--scott
--
"C'est un Nagra. C'est suisse, et tres, tres precis."
To clarify...
I realize you can accomplish this if you use zero as the first
parameter, and then specify a start time to start trimming...
Just wondering if there's a way to supply only the amount of trim
time, which would be a little easier for me.
Thanks!
> In article
> <a219505b-01bd-4238...@e35g2000yqc.googlegroups.com>
> , Jonathan <gosto.d...@gmail.com> wrote:
>>Sorry for this basic question, but is there a simple way to use
>>the trim function in Sox to remove a specified amount of time off
>>the *end* of a WAV file?
>>Let's say 2 seconds, for example.
>>
>>Is it necessary to know exactly how far into the file you want to
>>start trimming, or is there a way to just plug in 2 seconds as a
>>parameter?
>>I have read the documentation, but I found it a bit confusing.
>
> sox infile outfile trim 0 0:0:2
This doesn't appear to do what the OP wanted. Your command will trim
from the start of the file to 2 seconds in. I think what the OP wants
is to trim, say, 2 seconds off the tail.
As far as I can tell, you need to tell sox where to start the trim, so
in this case you'd have to specify the time length of the tile minus 2
seconds. Like, for a 3 minute song:
sox infile outfile 0 0:02:58
> On 16 Jun 2011, klu...@panix.com (Scott Dorsey) wrote in rec.audio.pro:
>> sox infile outfile trim 0 0:0:2
>
> This doesn't appear to do what the OP wanted. Your command will trim
> from the start of the file to 2 seconds in. I think what the OP wants is
> to trim, say, 2 seconds off the tail.
man soxeffect
"trim start [length]
Trim can trim off unwanted audio from the beginning and end of
the audio. Audio is not sent to the output stream until the
start location is reached.
The optional length parameter tells the number of samples to
output after the start sample and is used to trim off the back
side of the audio. ***Using a value of 0 for the start parameter
will allow trimming off the back side only.***"
I have to RTFM *every* time I use sox. It's very powerful, but impossible
to remember all the commands and variations thereof, and there's nearly
always some trial and error before I get it to do what I want.
--
Anahata
ana...@treewind.co.uk --/-- http://www.treewind.co.uk
+44 (0)1638 720444
maybe you can use the "reverse" command twice...
like this:
sox infile.wav outfile.wav reverse trim 30 reverse
this will trim out the last 30 seconds of audio. A bit slow since the
program need to reverse the file twice but works lossly.
>
> To clarify...
> I realize you can accomplish this if you use zero as the first
> parameter, and then specify a start time to start trimming... Just
> wondering if there's a way to supply only the amount of trim time, which
> would be a little easier for me.
My understanding is that Scott's answer does this.
Looking back though, I have to agree the manual isn't too clear...
hehe, sorry... LOSSLESSLY...
> man soxeffect
>
> "trim start [length]
> Trim can trim off unwanted audio from the beginning and end of
> the audio. Audio is not sent to the output stream until the
> start location is reached.
>
> The optional length parameter tells the number of samples to
> output after the start sample and is used to trim off the back
> side of the audio. ***Using a value of 0 for the start
> parameter will allow trimming off the back side only.***"
>
> I have to RTFM *every* time I use sox. It's very powerful, but
> impossible to remember all the commands and variations thereof,
> and there's nearly always some trial and error before I get it to
> do what I want.
Yes, that's what the manual says, but it's language is a little
misleading. What it does is remove everything BUT the tail. At least
that's what's happening for me, with version 14.3.0 for Windows. The
command
sox test.wav test1.wav trim 0 5
...leaves me with only the last 5 seconds of the file, rather than
removing the last 5 seconds.
> like this:
>
> sox infile.wav outfile.wav reverse trim 30 reverse
>
> this will trim out the last 30 seconds of audio. A bit slow since
> the program need to reverse the file twice but works lossly.
You're right - I find that very recommendation in the manual:
"Unfortunately, you must know the length of the silence at the end of
your audio file to trim off silence reliably. A work around is to
use the silence effect in combination with the reverse effect. By
first reversing the audio, you can use the above-periods to reliably
trim all audio from what looks like the front of the file. Then
reverse the file again to get back to normal."
I just tried it and it seems to work perfectly.
Yeah...I discovered that :)
really? i don't readed the manual, i just searched for a "reverse"
command...
i don't expected this situation to be explained in the man.
In scripting terms the most reliable workaround will be allowing some
"algebra" in the parameters like this: "trim (end-30)"...
regards
alex
Yes, it's in there, although the description is for a slightly
different scenario. It describes using the "silence" command, which
supposedly will delete all silence at the end of the track (which may
be what the OP wants, anyway.) "Reverse" works with the "trim" command,
too - I tried it. The command line:
sox test.wav test1.wav reverse trim 10 reverse
...removes exactly the last 10 seconds of the file. I was worried that
the "reverse" command might do something negative to the file, but I
tested it by comparing a double-reversed version with the original, and
they are byte-for-byte identical.