Skip to main content

LUFS Model Recipes

Overview

The LUFS model can be used to classify different loudness of audio into distinct regions.

In the example below, we demonstrate how to use the LUFS model to detect that the provided audio doesn't contain segments that are either too quiet or too loud. Another use case for content moderation can be detecting disruptive moments such as loud music.

Pre-requisites

  • Deeptone with license key
  • Audio File(s) you want to process

Sample data

You can download this audio sample for the following examples.

Detect segments where audio is too quiet or loud - Example 1

Remember to add a valid license key before running the example.

In this example, you can use the transitions level output, which is optionally calculated when processing a file, to detect parts of the audio file where audio did not have moderate level of loudness.

from deeptone import Deeptone
from deeptone.deeptone import AUDIO_EVENT_POS_HUMAN_SOUNDS

# Set the required constants
VALID_LICENSE_KEY = None
FILE_TO_PROCESS = None
OUTPUT_PERIOD_MS = 512

# Initialize DeepTone
engine = Deeptone(license_key=VALID_LICENSE_KEY)

output = engine.process_file(
filename=FILE_TO_PROCESS,
models=[engine.models.LUFS],
output_period=OUTPUT_PERIOD_MS,
include_transitions=True
)["channels"]["0"]["transitions"]["lufs"]

for transition in output:
if transition["result"] != "moderate" and transition["timestamp_end"] - transition["timestamp_start"] > 1000:
print(f'Audio not loud enough from {transition["timestamp_start"] / 1000}s to {transition["timestamp_end"] / 1000}s')

After executing the script using our example file, you should see the following output:

Audio not loud enough from 10.624s to 12.672s
Audio not loud enough from 14.592s to 15.616s
Audio not loud enough from 20.928s to 22.144s
Audio not loud enough from 26.368s to 27.52s
Audio not loud enough from 28.224s to 29.696s

From these results, we can now listen to the mentioned segments of the audio and verify if those are indeed harder to listen to.

  • Overview
  • Detect segments where audio is too quiet or loud - Example 1