6

I am able to join and crossfade two audio files using SoX, like so:

sox file1.wav file2.wav outfile.wav splice -q `soxi -D file1.wav`,0.5

where the soxi substitution is fetching the duration of file1 and 0.5 is the length of the cross-fade. I am now trying to extend this to an arbitrary number of files, in order to string them together with short crossfades in between. There would seem to be 2 approaches: piping and scripting. Sox has a -p option telling it to treat it's output as piped (instead of writing a file). But, with many input and arguments per command, it's not clear how that output (and input?) gets assigned in subsequent commands. So far I've got the line below, which does not work, trying to extend to 3 files.

sox -p file1.wav file2.wav splice -q `soxi -D file1.wav`,0.5 | sox -p file3.wav outfile.wav splice -q `soxi -D file3.wav`,0.5

Your tips on sox piping and scripting would be greatly appreciated.

ted.strauss
  • 4,119
  • 4
  • 34
  • 57
  • Despite the fact that this is an old question, I'm providing a reference to a working solution for those that stumble across it: You can use the method as indicated [here](https://stackoverflow.com/questions/28652490/cross-fading-several-audio-files-using-sox/28670099#28670099) to crossfade multiple files into one. – Alexander Maas Jun 08 '20 at 09:17

1 Answers1

3

I have gotten most of the way there with

sox --combine concatenate *.wav _merge.wav splice -q 3,1

The splice effect at the end places the beginning of the cross-fade at 3 seconds into the first file, and uses 1 second as cross-fade duration (half second at beginning and end of two files). This method is a temporary fix as I can choose to include only ~3 second files in my output (using other methods). A better answer would figure out how to grab duration of current file and substitute that in place of the 3.

sox --combine concatenate *.wav _merge.wav splice -q $(soxi −D {}),1

If the {} here selected the current item (as in find), that would do it. But that doesn't seem to work.

ted.strauss
  • 4,119
  • 4
  • 34
  • 57
  • Yes, this dont work, any chance that you find solution for crossfading banch of files. Thanx, im desperate to do this kind o batch, got so many file to process.Please help – user642523 Nov 20 '14 at 20:06
  • this answer helped me put a fixed length intro on a recording automatically. Thanks! – naugtur Sep 24 '20 at 22:06