Batch mixing wav files in sox

63 Views Asked by At

i would like to be able to batch mix a bunch of wav files i have in a folder using a bat file with sox..

basically in that folder i have 2 versions of every file, let's say a file named "Brother.wav" and a file named "Brother (2).wav". I would like them both mixed and creating a new "Brother (3).wav" file, and i would need this to happen to every file in the folder, so if i also have a file named "Sister.wav" and a file named "Sister (2).wav" in that folder, it would also work on it to create a "Sister (3).wav" mixed wav file, and so on. The thing is i have no idea what i should write in the bat file for this to work, or even if that is a possibility

What i have so far in my bat file is this:

"C:\Program Files (x86)\sox-14-4-2\sox.exe" -m *.wav *(2).wav  input3.wav

which doesn't do what i want, because it takes ALL the .wav in the folder and mix them together to create a single wav file named input3...

I'm sorry as this is probably a very noob issue, and i'm probably not explaining it properly, but i'm not used to using sox and bat files at all and i really need a way to automate that mixing process since i have a ton of files to go through :/

Thanks in advance for any answers!

1

There are 1 best solutions below

0
Magoo On

One-liner:

FOR %%e IN ("* (2).wav") DO FOR /f %%y IN ("%%e") DO IF EXIST %%y.wav ECHO "C:\Program Files (x86)\sox-14-4-2\sox.exe" -m %%y.wav %%e "%%y (3).wav"

Note that the sox line will simply be ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO "C:\Prog… to "C:\Prog… to actually process the files.

It's a matter of approach. *.wav means ALL .wav files, hence the results you report.

This solution uses the characteristics of for in two ways. Documentation about for can be obtained by executing for /? from the prompt - or thousands of examples on SO.

First, FOR %%e IN ("* (2).wav") DO assigns the name of each file matching * (2).wav to %%e in turn. The mask is quoted as it contains Space. (I was impressed that this actually worked! Normally, I'd have used a dir command to find filenames) and also because the mask contains ) (which would close the for…( unless quoted or escaped).

So - why use * (2).wav? The (2) file must exist for the process to be executed, so all we need to do having obtained those names is to find out whether the * exists, then assemble the required sox command.

Next, FOR /f %%y IN ("%%e") DO uses the default tokens=1 and Space delimiter to assign the * part to %%y.

Then we test whether %%y.wav exists, and if it does, execute sox with parameters constructed from the parts.