Sox : merge two audio files with a pad

纵饮孤独 提交于 2019-12-03 04:05:25

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.

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

Here is another solution benefiting from the use of double-quotes. It makes the command much more readable and very easy to extend:

sox −−combine sequence  "|sox input/odin.wav -p pad 0 1" "|sox input/dva.wav -p pad 0 1" "|sox input/tri.wav -p pad 0 1" output/test.wav

This would concatenate all three files, with a 1-second pause after each (odin, silence, dva, silence, tri, silence.)

Applied to the original post, we'd get:

sox −−combine sequence  "|sox long.ogg -p pad 0 6" "|sox short.ogg -p pad 0 1" newfile.ogg

(Tested OK on SoX 14.4.1 on Windows.)

I have hardly seen any SoX example using double-quotes, so I hope this helps someone!

Ran across delay command as well.

You could do the following: sox.exe -m short.ogg long.ogg delay 6

This will merge the two files and short.ogg will start 6 seconds into long.ogg

Because I'm not allowed to comment yet, I would just like to say that I like Fabien's answer because it can also be used with the "NULL" soundfile: e.g.,

sox --combine concatenate "|sox -n -p synth 1 sine 300" "|sox -n -p synth 1 sine 400" useful.wav

Will write 1 second of a sine tone at 300 Hz followed by 1 second of a sine tone at 400 Hz and write it to the file "useful.wav".

sox -n -p synth 1 sine 300 | sox --combine concatenate - farts.wav synth 1 sine 400

Will only write 1 second of a sine wave at 400 Hz to the file "farts.wav". The file is missing the first sine wave at 300 Hz.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!