2

I have about 20 audio files(.wav) in a folder , this is how I combine this wave files

sox *.wav output.wav

I want to add delay or silence between each wave .

I have tried pad , but it's just put the silence only at the start and end of output.wav .

andrew.46
  • 37,085
  • 25
  • 149
  • 228
zey
  • 123
  • 1
  • 1
  • 5

2 Answers2

5

You need to insert a silent track between each track as you specify them so you end up with something like:

sox track1.wav silence.wav track2.wav silence.wav ... output.wav 

You can do that manually (as above), or we can loop the current directory with an inline for-loop. Something like this should work:

sox -n -r 44100 -c 2 /tmp/silence.wav trim 0.0 2
sox $(for f in *.wav; do echo -n "$f /tmp/silence.wav "; done) output.wav

The silence-generator is stolen from here.

Oli
  • 289,791
  • 117
  • 680
  • 835
  • Sry friend seems same solution in same time, lol, same stolen – Maythux Jun 03 '15 at 12:17
  • script with `loop` works :) Thanks a lot – zey Jun 03 '15 at 12:17
  • When the number of `trackN.wav` is very large (e.g. `1000`), `Too many open files` error occurs because `sox` tries to open `silence.wav` the number of times specified as command-line arguments. To avoid this, you can generate multiple silent files (i.e. `silence_1.wav`, `silence_2.wav`, ...) and iteratively or randomly use them (e.g. `/tmp/silence_$((RANDOM % 10)).wav`). – ynn Jan 07 '23 at 04:32
3

Generate 2 seconds of (stereo) silence

sox -n -r 44100 -c 2 silence.wav trim 0.0 3.0

Combining the files

sox silence.wav filetopad.mp3 silence.wav output.wav

source http://activearchives.org/wiki/Padding_an_audio_file_with_silence_using_sox

Another possible solution

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

sox starts-last.mp3 -p pad 2 0 | sox - -m starts-second.mp3 -p pad 2 0 | sox - -m starts-first.mp3 combined.mp3
Maythux
  • 82,867
  • 54
  • 239
  • 271