Get Started

Normalizing an audio file with PyDub

Sometimes you'll have audio files where the speech is loud in some portions and quiet in others. Having this variance in volume can hinder transcription.

Luckily, PyDub's effects module has a function called normalize() which finds the maximum volume of an AudioSegment, then adjusts the rest of the AudioSegment to be in proportion. This means the quiet parts will get a volume boost.

You can listen to an example of an audio file which starts as loud then goes quiet, loud_then_quiet.wav, here.

In this exercise, you'll use normalize() to normalize the volume of our file, making it sound more like this.

This is a part of the course

“Spoken Language Processing in Python”

View Course

Exercise instructions

  • Import AudioSegment from PyDub and normalize from the PyDub's effects module.
  • Import the target audio file, loud_then_quiet.wav and save it to loud_then_quiet.
  • Normalize the imported audio file using the normalize() function and save it to normalized_loud_then_quiet.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import AudioSegment and normalize
from pydub import ____
from pydub.effects import ____

# Import target audio file
loud_then_quiet = AudioSegment.from_file(____)

# Normalize target audio file
normalized_loud_then_quiet = ____(____)

This exercise is part of the course

Spoken Language Processing in Python

AdvancedSkill Level
4.7+
3 reviews

Learn how to load, transform, and transcribe speech from raw audio files in Python.

Not all audio files come in the same shape, size or format. Luckily, the PyDub library by James Robert provides tools which you can use to programmatically alter and change different audio file attributes such as frame rate, number of channels, file format and more. In this chapter, you'll learn how to use this helpful library to ensure all of your audio files are in the right shape for transcription.

Exercise 1: Introduction to PyDubExercise 2: Import an audio file with PyDubExercise 3: Play an audio file with PyDubExercise 4: Audio parameters with PyDubExercise 5: Adjusting audio parametersExercise 6: Manipulating audio files with PyDubExercise 7: Turning it down... then upExercise 8: Normalizing an audio file with PyDub
Exercise 9: Chopping and changing audio filesExercise 10: Splitting stereo audio to mono with PyDubExercise 11: Converting and saving audio files with PyDubExercise 12: Exporting and reformatting audio filesExercise 13: Manipulating multiple audio files with PyDubExercise 14: An audio processing workflow

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free