Batch-converting audio files to be louder (on Linux)
February 28, 2015 [bash, Programming, STL]My mp3 player is very quiet, so I wanted to make all my podcasts as loud as possible.
First I ran this to get the programs I needed:
sudo apt-get install libav-tools normalize-audio
To convert each file I made a script that makes a "loud" directory, and puts the loud version of a file inside there. It uses the normalize-audio command to do it.
Note that this script encodes your (now louder) podcasts into Ogg Vorbis format at 50kb/s, which is quite low quality.
#!/bin/bash set -e set -u FILE="$1" DIR=`dirname "$FILE"` FILENAME=`basename "$FILE"` WAV_FILENAME="${FILENAME}.wav" LOUD_DIR="$DIR/loud" WAV_FILE="$LOUD_DIR/$WAV_FILENAME" LOUD_FILE="$LOUD_DIR/$FILENAME" mkdir -p "$LOUD_DIR" avconv -loglevel quiet -i "$FILE" "$WAV_FILE" normalize-audio -q -a 1 "$WAV_FILE" avconv -loglevel quiet -i "$WAV_FILE" -c:a libvorbis -b:a 50k "$LOUD_FILE" rm "$WAV_FILE"
Finally I placed a Makefile in the directory containing podcasts directories, like this:
MP3S := $(wildcard *.mp3) LOUD_MP3S := $(MP3S:%.mp3=loud/%.mp3) OGGS := $(wildcard *.ogg) LOUD_OGGS := $(OGGS:%.ogg=loud/%.ogg) all: $(LOUD_OGGS) $(LOUD_MP3S) loud/%.ogg: %.ogg loud "$<" loud/%.mp3: %.mp3 loud "$<"
Now I can make loud versions of all podcasts by just cding into the directory containing the Makefile, and typing make. By the power of make, it only converts files that have not already been converted.