-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwavFormatTo16-44.cmd
More file actions
78 lines (63 loc) · 2.25 KB
/
wavFormatTo16-44.cmd
File metadata and controls
78 lines (63 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@echo off
setlocal enabledelayedexpansion
echo ###################################################
echo # Description: Convert audio files to 16-bit 44.1kHz format
echo # Usage: wavFormatTo16-44.cmd /path/to/audio.wav [custom args]
echo # wavFormatTo16-44.cmd /path/to/audio/files/ [custom args]
echo # Param 1: Audio file or directory
echo # Param 2+ [Optional]: Custom args for SoX
echo # Requires: SoX
echo ###################################################
echo.
@REM ################################################################################
@REM # check parameters & set defaults
@REM ################################################################################
set defaultArgs=-b 16 -r 44100
@REM Check 1st arg
IF "%~1"=="" (
echo Error: 1st arg must be an audio file or directory
exit /b 1
)
set inputPath=%1
@REM Get remaining args for SoX
set soxArgs=
if "%2"=="" (
@REM Check optional 2nd arg and provide default value
set soxArgs=%defaultArgs%
echo ### Using default args: %defaultArgs%
) else (
@REM Use all arguments after the first one
set "allArgs=%*"
for /f "tokens=1,* delims= " %%a in ("!allArgs!") do set "soxArgs=%%b"
echo ### Using user-defined args: !soxArgs!
)
@REM ################################################################################
@REM Check if path is a directory or a file
@REM ################################################################################
if exist "%inputPath%\" (
@REM Process directory
echo.
echo Processing all audio files in directory: %inputPath%
@REM Process all audio files in the directory
for %%F in ("%inputPath%\*.wav" "%inputPath%\*.aif" "%inputPath%\*.aiff" "%inputPath%\*.mp3" "%inputPath%\*.flac") do (
echo.
echo Processing: %%F
CALL :ProcessFile "%%F" "%soxArgs%"
)
echo.
echo Finished converting all audio files in directory: %inputPath%
) else (
@REM Process single file
CALL :ProcessFile "%inputPath%" "%soxArgs%"
)
exit /b 0
:ProcessFile
@REM Process a single audio file
set "filename=%~1"
set "args=%~2"
set "outputFile=%~dpn1_16-44%~x1"
echo Converting: %filename%
@REM Do conversion
sox "%filename%" %args% "%outputFile%"
echo Success: Converted to 16/44.1: %outputFile%
exit /b 0