isidroco - 2022-09-12

My current workaround:

@echo off
set _soxExe="c:\AUDIO\UT\SOX\sox.exe"
verify other 2>nul & REM sets errorlevel to 1, check if enableextensions works
setlocal enableextensions enabledelayedexpansion & REM to get var value at exec with !varNm!
if %errorlevel%==1 ( echo ERROR newer cmd.exe is needed & goto :fin )
if exist "%~f1" if exist "%~f2" goto :ok12
  echo .
  echo . mix2stereo v22.0914
  echo .
  echo . Usage:  mix2stereo audioFile1 audioFile2 [flac|wav]
  echo .
  echo . Makes stereo from 2 audiofiles
  echo .   Left from audioFile1 1st channel
  echo .   Right from audioFile2 1st channel
  echo .   Output Name: audioFile1_stereo
  echo .   Output Audio File Format is wav or flac, unless
  echo .       specified is same as audioFile1 if possible
  echo .
  echo . This help shown if any audioFile missing.
  echo . Needs SOX.EXE path on line 2
  echo .
  goto :fin
:ok12
  if not exist %_soxExe% echo ERROR set SOX.EXE location on line 2 &goto :fin
  echo Input files: %~f1; %~f2
  set chanR=0&    rem Will have file1 #channels + 1; that will point to 1st channel of file 2
  set _command=%_soxExe% --info "%~f1" 2^>nul
  rem echo "!_command!"
  rem Parse file1 audio info searching for "channels: ??"
  rem https://stackoverflow.com/questions/62972917/batch-script-usage-of-for-f-with-spaces-in-command-and-usebackq
  for /f "tokens=1-3* delims=: " %%A in ('^"!_command!^"') do (
    rem echo %%A--%%B--%%C--%%D
    if /i "%%A"=="channels" ( echo ** Valid %~n1 with %%B channels
      set /a chanR=%%B+1
    )
  )
  if !chanR! lss 2 ( echo ERROR not audio file: %~f1 & goto :fin )
  set outExt=%~x1&  rem Default to file1 extension
  if .%3==.flac set outExt=.flac
  if .%3==.wav set outExt=.wav
  if /i not !outExt!==.wav if /i not !outExt!==.flac set outExt=.wav& rem use .wav if invalid
  rem Generate output: -M == --combine merge  -S == --show-progress
  rem %~dpn1 is file1 Drive+Path+Name with no extension
  rem echo %_soxExe% --no-clobber -S -M "%~f1" "%~f2" "%~dpn1_stereo.wav" remix -m 1 !chanR!
  %_soxExe% --no-clobber -S -M "%~f1" "%~f2" "%~dpn1_stereo!outExt!" remix -m 1 !chanR! stat
  if exist "%~dpn1_stereo!outExt!" (
    echo **OK: "%~dpn1_stereo!outExt!"
  ) else (
    echo *ERROR not generated: "%~dpn1_stereo!outExt!"
  )
:fin
pause
 

Last edit: isidroco 2022-09-14