Sox : merge two audio files with a pad

≯℡__Kan透↙ 提交于 2019-12-03 14:15:43

问题


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.


回答1:


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.




回答2:


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



回答3:


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!




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/5587135/sox-merge-two-audio-files-with-a-pad

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