Ketcomp
Ketcomp

Reputation: 454

Making chunks of audio files using SoX if start and end times are known

I have a 10 minute audio which I want to break in chunks of time as follows: (the format is mm:ss.frac)

 1. 1.wav -> 00.000 - 20.271
 2. 2.wav -> 20.272 - 47.550
 3. 3.wav -> 47.551 - 01:20.562

I tried using the trim command like such

sox infile outfile trim 0.000 20.271 However the format is trim start [length]

Worst case, I will have to calculate the durations for individual chunks. Is there another way?

Upvotes: 2

Views: 3092

Answers (2)

Ketcomp
Ketcomp

Reputation: 454

I found that the simplest solution is to write the command as such:

sox infile outfile start =end

The audio is not sent to the output stream until the start location is reached and specifying an end location can be done by using the "=" sign with the end time.

So the code would now be, for instance:

sox forth.wav 10.wav trim 303.463 =353.790
  1. Link to the docs http://manpages.ubuntu.com/manpages/precise/man1/sox.1.html
  2. Relevant excerpt:

trim start [length|=end] The optional length parameter gives the length of audio to output after the start sample and is thus used to trim off the end of the audio. Alternatively, an absolute end location can be given by preceding it with an equals sign. Using a value of 0 for the start parameter will allow trimming off the end only.

Upvotes: 4

viraptor
viraptor

Reputation: 34145

No, you have to calculate the length if you want to use sox. You could also use ffmpeg instead which has atrim filter that supports start/end times.

Upvotes: 0

Related Questions