When we are processing wav audio files, we may need know the loudness of a wav file. In this tutorial, we will introduce how to compute it using python.
Preliminary
We will use python pyloudnorm library to compute it, we should install it.
pip install pyloudnorm
pyloudnorm allows us to compute loudness meter of an audio file based on ITU-R BS.1770-4.
How to compute the loundess of a wav file?
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)
In this example, we will use python soundfile to read the wav data. You also can use scipy.io.wavfile.read() or librosa.load() to read. Here is a tutorial:
The Difference Between scipy.io.wavfile.read() and librosa.load() in Python – Python Tutorial
Then we will use meter.integrated_loudness() to compute loudess of this wav file.
Run this code, you will see:
(3097680,) -24.417673019066093
As to our wav file:0055014.wav, it is a single channel audio.
The loudness of this wav file is -24.