Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

How do you trim the audio file's end using SoX?

Using Sox, how do I shorten an audio file by 5 seconds, trimming from the end?

For example, this is how to trim a file from the beginning:

    sox input output trim 5000

This is how to add 5 seconds of silence to the end:

    sox input output pad 0 5000
question from:https://stackoverflow.com/questions/9667081/how-do-you-trim-the-audio-files-end-using-sox

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The syntax is sox input output trim <start> <duration>

e.g. sox input.wav output.wav trim 0 00:35 will output the first 35 seconds into output.wav.

(you can know what the length is using sox input -n stat)

From the SoX documentation on the trim command:

Cuts portions out of the audio. Any number of positions may be given; audio is not sent to the output until the first position is reached. The effect then alternates between copying and discarding audio at each position. Using a value of 0 for the first position parameter allows copying from the beginning of the audio.

For example,

sox infile outfile trim 0 10

will copy the first ten seconds, while

play infile trim 12:34 =15:00 -2:00

and

play infile trim 12:34 2:26 -2:00

will both play from 12 minutes 34 seconds into the audio up to 15 minutes into the audio (i.e. 2 minutes and 26 seconds long), then resume playing two minutes before the end of audio.

Per dpwe's comment, the position values are interpreted as being relative to the previous position, unless they start with = (in which case they are relative to the start of the file) or - (in which case they are relative to the end of the file).

So, trimming five seconds off the end would be sox input output trim 0 -5


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...