Sox scripting

For those that know a little scripting and know about Sox… here’s my little script that splits files into 2 minute chops and converts the result to the s2400 default sample rate and bit depth. Maybe you can use some of this to create something similar for yourself…

@ECHO OFF
echo Splitter start
call :treeProcess
echo Splitter done
goto :eof

:treeProcess
call :splitAndConvertProcess
for /D %%d in (*) do (
    cd %%d
	echo dir: "%%d"
    call :treeProcess
    cd ..
)
exit /b

:splitAndConvertProcess
mkdir tmpSoxxx
for %%f in (*.wav,*.flac,*.mp3) do (
	echo	splitting file: "%%f"
    "C:\Program Files (x86)\sox-14-4-2\sox.exe" -V1 "%%f" "tmpSoxxx\%%~nf_.wav" trim 0 120 : newfile : restart
	del "%%f"
)
cd tmpSoxxx
for %%f in (*.wav) do (
	echo	converting file: "%%f"
    "C:\Program Files (x86)\sox-14-4-2\sox.exe" -V1 -G "%%f" -b 16 -r 48000 "..\%%f"
	del "%%f"
)
cd ..
rmdir tmpSoxxx
exit /b

4 Likes

Here another one for just resampling to 16bit 48kHz recursively (and destructively)

@ECHO OFF
echo Converter start
call :treeProcess
echo Converter done
goto :eof

:treeProcess
call :convertProcess
for /D %%d in (*) do (
    cd %%d
	echo dir: "%%d"
    call :treeProcess
    cd ..
)
exit /b

:convertProcess
mkdir tmpSoxxx
for %%f in (*.wav,*.flac,*.mp3) do (
	echo	resampling file: "%%f"
    "C:\Program Files (x86)\sox-14-4-2\sox.exe" -V1 -G "%%f" -b 16 -r 48000 "tmpSoxxx\%%~nf.wav"
	del "%%f"
)
cd tmpSoxxx
for %%f in (*.wav) do (
	echo	moving file: "%%f"
	move "%%f" "..\%%f" 
)
cd ..
rmdir tmpSoxxx
exit /b

2 Likes