#!/bin/bash
# This command is for normalizing the amplitude of an audio file.
# See the stat option in the sox man page for more info.
# sox writes the normalization factor on stderr.  

tmpfile=/tmp/swnorm.tmp

# Find the amount we need to normalize by.
sox -c 1 -t raw -s -w -r 44100 $1 -e  stat -v 2> $tmpfile

# Normalize and write to a temp file.
sox -v $(<$tmpfile) -c 1 -t raw -s -w -r 44100 $1 -t raw -s -w -c 1 $tmpfile

# Replace the original with the temp file.
mv $tmpfile $1



