pyloudnorm

0.2.0 · active · verified Thu Apr 09

pyloudnorm is an active Python library (version 0.2.0) that provides an implementation of the ITU-R BS.1770-4 loudness algorithm. It enables flexible and programmatic control over loudness measurement parameters, including integrated loudness (LUFS) and Loudness Range (LRA). The library is primarily feature-driven, with recent major updates introducing new capabilities and refining Python compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `pyloudnorm.Meter` and measure the integrated loudness (LUFS) and Loudness Range (LRA) of a dummy audio signal. It highlights the primary API calls for basic loudness analysis.

import numpy as np
import pyloudnorm as pyln

# Create dummy mono audio data (e.g., 2 seconds at 44.1 kHz)
sample_rate = 44100  # Hz
duration = 2.0      # seconds
channels = 1        # mono
data = np.random.uniform(-0.5, 0.5, int(sample_rate * duration))

# pyloudnorm expects a 2D array (samples, channels) if multi-channel,
# or 1D array for mono if you adjust it.
# For integrated_loudness, a 1D mono signal works directly.

# Create a BS.1770 meter
meter = pyln.Meter(sample_rate)

# Measure the integrated loudness
loudness = meter.integrated_loudness(data)

print(f"Integrated Loudness: {loudness:.2f} LUFS")

# Example for Loudness Range (LRA) - requires sufficient audio length
# (Often more than 2 seconds, but demonstrating usage)
lra = meter.loudness_range(data)
print(f"Loudness Range: {lra:.2f} LU")

view raw JSON →