How to normalize sound in mp3 files

Solution 1:

Take a look @ mp3gain which for me is even better than normalize-audio

mp3gain -r *.mp3

another useful version could be the -c which prevent to ask if you want to do the changes for many files:

mp3gain -c -r *.mp3

as said in the man page:

mp3gain does not just do peak normalization, as many normalizers do. Instead, it does some statistical analysis to determine how loud the file actually sounds to the human ear. Also, the changes mp3gain makes are completely lossless. There is no quality lost in the change because the program adjusts the mp3 file directly, without decoding and re-encoding.

Note: That package was removed on purpose on ubuntu 15.04.

Debian proposes the python-rgain package as replacement (The advantage is that 'replaygain' supports several file formats, namely Ogg Vorbis , Flac, WavPack and MP3. Also, it allows you to view existing Replay Gain information in any of those file types). After installing it, run replaygain.

To install python-rgain from the terminal, run the command

sudo apt-get install python-rgain

Noted lately the binary file is replaygain

Alternatively, get the .deb file for 14.04 (the latest) from here. Install as usual. After that, you need to run sudo apt-get -f install to correct some dependencies issues.

Solution 2:

Audacity

With Audacity we can easily batch process files to apply conversions or effects to many files in a list. To do so we first have to define a "Chain" containing the effects we want to apply.

This is done with "File --> Edit Chains...". In the now opening window press the Add button on the bottom left to insert a new chain (give it a sensible name):

enter image description here

Then choose the effect and it's parameters to insert to the chain (here shown for default values and the Normalize effect).

Important: we always need to also add the effect "Export MP3" (or any other export format) for saving the resulting conversion to disk.

When done leave this window with OK to open "File --> Apply Chain...". Select the Chain we have just created and load all files you need with "Apply to files...". Several files can be selected from the file chooser that opens.

enter image description here

Processed files will be saved in a new subdirectory "cleaned" in the original's path.


SoX

From version > 14.3 we can use the sox filter --norm for normalizing audio on the command line or for batch processing:

sox --norm infile outfile

MP3-support is added to Sox with libsox-fmt-all:

sudo apt install sox libsox-fmt-all

Solution 3:

I would use this project Normalize, it's a command-line tool for normalizing audio files. Looks to be exactly what you need. Can do batch processing and doesn't require resampling to intermediate formats.

It's in the package repos as normalize-audio, sudo apt-get install normalize-audio. This is a build maintained upstream by Debian so it should be in anything LTS or newer and is built with mp3 compatibility (tested). There is a good manpage man normalize-audio to explore the options but the commands defaults appear to work well. For batch processing (normalize volume across multiple files), normalize-audio -b *.mp3 or specify individual filenames instead of using wildcards.

Solution 4:

rgain3 (formerly replaygain/rgain )

2020 update: replaygain/rgain is currently not being developed, try rgain3, a modern fork. Here on pip.

Install: pip install rgain3, then run replaygain as usual.


replaygain is faster and easier:

This package provides a Python package to calculate the Replay Gain values of audio files and normalize the volume of those files according to the values. Two basic scripts exploiting these capabilities are shipped as well.

Replay Gain is a proposed standard designed to solve the very problem of varying volumes across audio files.

Install: sudo apt install python-rgain.

replaygain --force *.mp3
  • -f, --force Recalculate Replay Gain even if the file already contains gain information.

Since only calculate/change replaygain value, is also faster: With an average PC (Intel i7-6500U, 8GB RAM) the rate was ~20 files/minute.

Reference

  • ReplayGain article at Wikipedia
  • python-rgain at Launchpad

Solution 5:

For the sake of it, I'll throw my 2 cents in. I was looking for exactly the same thing (only for ogg files) and started a thread at Crunchbang Forum. You can view it here: Normalize-audio can't find mp3 decoder

Basically my solution was the script in post #8. It works for mp3, flac, and ogg input files, possibly others but definitely not wav.

Just create a file (name it whatever you want, I called mine db_adjust_mp3), chmod +x , and stick it in your ~/bin folder. It fills in any missing codec data as well. Example:

Original file: 16._This_Protector.mp3: Audio file with ID3 version 2.3.0, contains:

vs.

Normalized file: 16._This_Protector.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo

I've modified the script to use normalize-mp3 here so you can use it if you want:

#!/bin/bash

find "$1" -iname "*.""$2" > $HOME/file_list

cat $HOME/file_list | while read line; do
#  echo "$line"
  orig_gain="$(normalize-mp3 -n "$line" | cut -d 'd' -f1)"
  larger=$(echo "$orig_gain"'>'-12 | bc)
  if [[ larger ]]
    then
      gain_difference=$(echo "$orig_gain"*-1-12 | bc)
    else
      gain_difference=$(echo "$orig_gain"-12 | bc)
  fi
  echo "Gain Difference will be: $gain_difference""db"
  normalize-ogg --mp3 --bitrate "$3" -g "$gain_difference""db" -v "$line"
done

This script calculates the difference between the current db level and -12db, then applies a gain adjustment to put the gain at exactly -12db, which is what I've found works the best for me. It is recursive as well, which makes it great for doing entire music collections or files in many subfolders. If you wish to set a different db level, just change the both instances of the number "12" to whatever db level you would like to use. As I posted in my Crunchbang thread, usage is as follows:

normalize-mp3 <directory> <file extenstion(with no leading dot)> <bitrate>

However, when I used to keep my music library in mp3 format, I used to use mp3gain as well, just as Philippe suggested. The dead simplicity of it is great and I really liked it. The problem with normalize-audio though is that it does decode an re-endcode the files, so there is some sound degradation. But unless you're an audiophile and your mp3's are encoded at a high bitrate you shouldn't notice much difference.

The thing I noticed with mp3gain though was that no matter what options I tried I couldn't get everything in my collection to be exactly the same db level, which is what I want so that I never have to adjust the volume from one track to the next. This script does exactly that. Sorry for being so long winded. Hope this helps.