Skip to content

Instantly share code, notes, and snippets.

@coltenkrauter
Created October 24, 2019 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coltenkrauter/50d088c516d78527696682d60379fdf2 to your computer and use it in GitHub Desktop.
Save coltenkrauter/50d088c516d78527696682d60379fdf2 to your computer and use it in GitHub Desktop.
Python code for normalizing audio files.
# Credit: https://stackoverflow.com/questions/42492246/how-to-normalize-the-volume-of-an-audio-file-in-python-any-packages-currently-a#answer-42496373
# pip install pydub
from pydub import AudioSegment
def match_target_amplitude(sound, target_dBFS):
change_in_dBFS = target_dBFS - sound.dBFS
return sound.apply_gain(change_in_dBFS)
sound = AudioSegment.from_file("yourAudio.m4a", "m4a")
normalized_sound = match_target_amplitude(sound, -20.0)
normalized_sound.export("nomrmalizedAudio.m4a", format="mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment