简体   繁体   中英

Batch process two WAV files with one letter difference?

How can I batch process files with identical names, minus a single letter difference ( c or t )?

 BML201_solohorn_longs_legato_ff_RR1_c_G4.wav BML201_solohorn_longs_legato_ff_RR1_t_G4.wav BML201_solohorn_shorts_staccato_ff_RR2_c_C#3.wav BML201_solohorn_shorts_staccato_ff_RR2_t_C#3.wav

Using sox , this code lowers volume on one microphone file then merges both into a new file:

sox -v 0.43 tree.wav -m close.wav output.wav

I need to output to a subfolder using the original file names, or worse case just overwrite the original c files.

@AlexP @Stephan

It's working beautifully! :)

For whatever reason it wasn't working with the custom file name out. I didn't want to remove the delimiter anyway (long story why), so I just used the same file name and now it works. Here's the code if anyone else could use it.

@echo off
  setlocal enableextensions disabledelayedexpansion
  for %%f in (*_c_*.wav) do call :processOneFile "%%~f"
  exit /b

:processOneFile

  setlocal
  echo;- Looking at "%~nx1"
  cd /d "%~dp1"
  set "fileNameC=%~nx1"

  set "fileNameT=%fileNameC:_c_=_t_%"
  echo;  Found "%fileNameT%"

  mkdir mixed >nul 2>&1

  echo;  Running sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "mixed\%fileNameOut%"
  sox -v 0.43 "%fileNameT%" -m "%fileNameC%" "mixed\%fileNameC%"
  echo;
  exit /b

Sorry to be that annoying pest. I usually hate when people don't help themselves in another language I semi-know. So I get it. I just had no idea where to start and reading up on Batch was murdering my brain. Anyway, thanks for the help to all and thanks to AlexP for the solution! :) -Sean

    @echo off
    setlocal enableextensions disabledelayedexpansion
    rem
    rem Run this script in the directory where the _c_ and _t_ files reside.
    rem
    for %%f in (*_c_*.wav) do call :processOneFile "%%~f"
    exit /b

:processOneFile

    setlocal
    echo;- Looking at "%~nx1"
    cd /d "%~dp1"
    set "fileNameC=%~nx1"
    rem
    rem Now %fileNameC% is the name of the file with _c_. Calculate the name
    rem of the corresponding file with _t_ and check that it actually exists.
    rem
    set "fileNameT=%fileNameC:_c_=_t_%"
    if not exist "%fileNameT%" (
      echo;  Cannot find "%fileNameT%"
      echo;
      exit /b
    )
    echo;  Found "%fileNameT%"
    rem
    rem Calculate the name of the output file and the name of the subdirectory.
    rem This example code makes the name of the output file by replacing
    rem _c_ with _ in the name of %fileNameC%, and makes the name of the
    rem subdirectory by deleting the extension .wav from the name of the output
    rem file. Adjust to suit your needs.
    rem
    set "fileNameOut=%fileNameC:_c_=_%"
    for %%d in ("%fileNameOut%") do set "subDirName=%%~nd"
    rem
    rem Create the subdirectory %subDirName% if it does not exist. If the
    rem subdirectory already contains a file named %fileNameOut% delete it.
    rem
    mkdir "%subDirName%" >nul 2>nul
    del "%subDirName%\%fileNameOut%" >nul 2>&1
    rem
    rem Do something with "%fileNameC%" and "%fileNameT%" producing an output
    rem file %subDirName%\%fileNameOut%.
    rem I don't know what you want to do with them, maybe
    rem sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "%subDirName%\%fileNameOut%"
    rem
    rem Insert your command here.
    rem
    echo;
    rem
    rem All done with these two files, return to the main loop to process the
    rem next two.
    rem
    exit /b

This is my edit of AlexP's code. It doesn't do anything to the files (likely my fault). Am I correct in using "merged\\" if I just want to put all files in the same subdirectory at least?

@echo off
  setlocal enableextensions disabledelayedexpansion
  for %%f in (*_c_*.wav) do call :processOneFile "%%~f"
  exit /b

:processOneFile

  setlocal
  echo;- Looking at "%~nx1"
  cd /d "%~dp1"
  set "fileNameC=%~nx1"

  set "fileNameT=%fileNameC:_c_=_t_%"
  echo;  Found "%fileNameT%"

  mkdir mixed >nul 2>&1

  set "fileNameOut=%fileNameC:_c_=_%"
  echo;  Running sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "mixed\%fileNameOut%"
  sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "mixed\%fileNameOut%"
  echo;
  exit /b

Sorry for the lack of clarity in the original question. I replied to the first answer with some clarifying remarks. I hope this helps. I'm happy to clarify more if needed. -Sean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM