Skip to content

Instantly share code, notes, and snippets.

@kampar
Created June 2, 2025 15:40
Show Gist options
  • Save kampar/b010e98ee5e85203e80b3076cec620b8 to your computer and use it in GitHub Desktop.
Save kampar/b010e98ee5e85203e80b3076cec620b8 to your computer and use it in GitHub Desktop.
BATCH file to convert all WAV files into 32kbps bitrate mp3 files. You need to install ffmpeg first. I use this file to convert all Google NotebookLM WAV files that soo huge, and I'm afraid my students will object with them, if I share the raw.
@echo off
REM wav_to_mp3_32kbps.cmd
REM Batch script to convert .wav files to .mp3 at 32kbps.
REM It skips conversion if a .32k.mp3 version of the file already exists.
SETLOCAL EnableDelayedExpansion
echo Starting WAV to MP3 conversion (32kbps)...
echo ============================================
REM Ensure ffmpeg is in your PATH or place ffmpeg.exe in the same directory as this script.
FOR %%f IN (*.wav) DO (
REM Get the filename without the .wav extension
SET "basename=%%~nf"
REM Define the target MP3 filename
SET "outputfile=!basename!.32k.mp3"
REM Check if the output file already exists
IF EXIST "!outputfile!" (
echo Skipping: "!outputfile!" already exists for "%%f".
) ELSE (
echo Converting "%%f" to "!outputfile!"...
ffmpeg -i "%%f" -b:a 32k -ar 44100 -ac 2 "!outputfile!"
REM Check if ffmpeg conversion was successful
IF ERRORLEVEL 1 (
echo [ERROR] Failed to convert "%%f". Check ffmpeg output.
REM Optionally, delete a partially created/failed output file
REM IF EXIST "!outputfile!" DEL "!outputfile!"
) ELSE (
echo [SUCCESS] Converted "%%f" to "!outputfile!".
)
)
echo. REM Adds a blank line for better readability
)
echo ============================================
echo Conversion process finished.
ENDLOCAL
pause
@kampar
Copy link
Author

kampar commented Jun 2, 2025

if you can read the batch file, the script is actually check if there is a file named like filename.32k.mp3 exist. if exist, skip this conversion. If no, convert this wav into filename.32k.mp3. This script will do it for every wav files within current directory /folder

The magic is at line #25, the conversion with ffmpeg.

So... make sure you've ffmpeg in your path fists.

@kampar
Copy link
Author

kampar commented Jun 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment