2

I'd like to merge a number of WAV files located in two separate directories.
The files are named identically, similar to the following example:

\DIRECTORY A
  C1-05.wav
  C2-05.wav
  C3-05.wav
  C4-05.wav
  C5-05.wav

\DIRECTORY B
  C1-05.wav
  C2-05.wav
  C3-05.wav
  C4-05.wav
  C5-05.wav

The idea is to merge file C1-05.wav from \DIRECTORY A with the corresponding file C1-05.wav from \DIRECTORY B, file C2-05.wav from \DIRECTORY A with the corresponding file C2-05.wav from \DIRECTORY B, and so on.

I started doing this with Audacity, file by file, but they are a lot. I was wondering if there is a way to do so with a script or from the command line.
I understand that it could be as simple as:


sox -m file1.wav file2.wav output_file.wav

But get mixed up when it comes to indicate sox how to sort the files in correct manner according to their matching names.

1 Answer 1

0
@echo off && cd /d "%~dp0"

set "_dir_A=D:\The\Full\Path\To\Your\DIRECTORY A"
set "_dir_B=D:\The\Full\Path\To\Your\DIRECTORY B"

set "_ffmpeg=C:\Program Files\FFmpeg\bin\ffmpeg.exe"
set "_ffmpeg="%_ffmpeg%" -hide_banner -v error -stats -y -i "
set "_ffargs=-filter_complex "[0:0][1:0]concat=n=2:v=0:a=1[out]" -map "[out]""

for /f usebackq^delims^= %%i in =;(` call 2^>nul "%__AppDir__%where.exe" "%_dir_A%:*.wav" 
    `);= do for /f usebackq^delims^= %%G in =;(` call 2^>nul "%__AppDir__%where.exe" "%_dir_B%:%%~nxi"
    `);= do <nul set /p "null=%%~nxG " & call <con: %_ffmpeg% "%%~fi" -i "%%~fG" %_ffargs% "%%~ni_.wav"

Keep in mind that the merged files will be saved in the folder where you saved this batch, if you want them to be saved elsewhere like \DIRECTORY C, just change the first line...

@echo off && cd /d "%~dp0"
:: to 
@echo off && cd /d "D:\The\Full\Path\To\Your\DIRECTORY C"

This will list the wav files in the first directory and in a first loop and then list the same name.wav in the second directory in the second loop, if it finds the same name.wav it will concatenate the two into a third file with the same name_.wav



Some further reading:

2
  • Awesome! Thanks a lot. Commented Jun 27 at 21:21
  • Thank you for testing and the other actions...
    – Io-oI
    Commented Jun 29 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .