Sox : merge two audio files with a pad

zopieux picture zopieux · Apr 7, 2011 · Viewed 11.4k times · Source

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.

Answer

icyrock.com picture icyrock.com · Apr 29, 2011

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.