Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sox : merge two audio files with a pad

I'm using the sox tool and I would like to merge two audio files, let's say long.ogg and short.ogg to output a file output.ogg. This is very easy using $ sox -m long.ogg short.ogg output.ogg.

Thing is, I would like the short.ogg to be played after n seconds (while long.ogg should start right from the beginning). To do so, I've found the pad effect. But I don't understand the syntax to delay only the short.ogg input file, not the long.ogg one.

I found a (dirty) way of doing so (with n=6):

$ sox short.ogg delayed.ogg pad 6
$ sox -m long.ogg delayed.ogg output.ogg

I would like not to have to create an intermediate file. Thanks in advance for your help.

like image 989
zopieux Avatar asked Apr 07 '11 20:04

zopieux


2 Answers

You should be able to do something like:

sox short.ogg -p pad 0 6|sox - long.ogg output.ogg

-p option to sox is used for piping - basically, it tells sox to use stdout as the output. Using - as the input to the second sox is actually saying input is stdin (which happens to be the stdout of the previous sox, as we are piping with |). pad 0 6 tells pad 0 seconds at the beginning and 6 seconds at the end.

Hope this helps.

like image 85
icyrock.com Avatar answered Sep 27 '22 22:09

icyrock.com


Thanks to icyrock, I managed to find a solution. I'm using:

$ sox short.ogg -p pad 6 0 | sox - -m long.ogg output.ogg

For multi tracks (credits to Orlando):

$ sox starts-last.mp3 -p pad 2 0 | sox - -m starts-second.mp3 -p pad 2 0 | sox - -m starts-first.mp3 combined.mp3
like image 20
zopieux Avatar answered Sep 27 '22 22:09

zopieux