Search code examples
audioconcatenationsox

Sox: concatenate multiple audio files without a gap in between


I am concatenating multiple (max 25) audio files using SoX with

sox first.mp3 second.mp3 third.mp3 result.mp3

which does what it is supposed to; concatenates given files into one file. But unfortunately there is a small time-gap between those files in result.mp3. Is there a way to remove this gap?

I am creating first.mp3, second.mp3 and so on before concatenating them by merging multiple audios(same length/format/rate):

sox -m drums.mp3 bass.mp3 guitar.mp3 first.mp3

How can I check and assure that there is no time-gap added on all those files? (merged and concatenated)

I need to achieve a seamless playback of all the concatenated files (when playing them in browser one after another it works ok).

Thank you for any help.

EDIT:

The exact example (without real file-names) of a command I am running is now:

sox "|sox -m file1.mp3 file2.mp3 file3.mp3 file4.mp3 -p" "|sox -m file1.mp3 file6.mp3 file7.mp3 -p" "|sox -m file5.mp3 file6.mp3 file4.mp3 -p" "|sox -m file0.mp3 file2.mp3 file9.mp3 -p" "|sox -m file1.mp3 file15.mp3 file4.mp3 -p" result.mp3

This merges files and pipes them directly into concatenation command. The resulting mp3 (result.mp3) has an ever so slight delay between concatenated files. Any ideas really appreciated.


Solution

  • This is my guess for your issue:

    • sox does not add time gap during concatenation,
    • however it add time-gap in other operations, for instance if you do a conversion before the concatenation.

    To find out what happens I suggest you to check all durations of your files at each time (you can use soxi for instance) to see what's going on.

    If it doesn't work (the time-gap is added during concatenation), let me please do another guess:

    • Sox add time gap because your samples at the beginning or at the end of the file are not close to zero.

    To solve this, you could use very short fade-in an fade-out on you files.

    Moreover, to force sox to output files with a well-defined length, you could use the trim parameter like this:

    sox filein.mp3 trim 0 duration fileout.mp3