Modify the Audio Loudness Using Python: A Step Guide – Python Tutorial

By | December 3, 2021

We have known python pyloudnorm can compute the loudness of an audio file, here is the tutorial:

Computing WAV Audio Loudness Meter Using Python – Python Tutorial

However, how to modify it? In this tutorial, we will introduce it for python beginners.

How to modify the audio loudness in python?

It is easy to implement this function in python pyloudnorm. Here is an example:

import soundfile as sf
import pyloudnorm as pyln

data, rate = sf.read("0055014.wav") # load audio (with shape (samples, channels))
print(data.shape)
meter = pyln.Meter(rate) # create BS.1770 meter
loudness = meter.integrated_loudness(data) # measure loudness
print(loudness)

# loudness normalize audio to -12 dB LUFS
loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -12)

sf.write("0055014-db.wav", loudness_normalized_audio, rate)

In this example, the loudness meter of 0055014.wav is -24, we will modify it to -12.

Notice

The higher the value of the loudness, the louder the volume of audio.

For example -12>-24, which means -12 is louder than -24.

Leave a Reply

Your email address will not be published. Required fields are marked *