Display Sound Amplitude in Python: A Step Guide – Python Librosa Tutorial

By | July 27, 2022

Sound amplitude gives us some very useful information when we are processing an audio file. In this tutorial, we will introduce you how to display it.

Read sound data using python librosa

We will use python librosa to read a sound file data. For example:

import numpy as np
import matplotlib.pyplot as plt
import librosa as lr


audio='arabic6'
y, sr = lr.load("drama-02-005.flac", sr = 16000, mono=True)
time = np.arange(0,len(y))/sr

In this example, we will read an audio with sample rate 16k. You can learn more on reading audio data in this tutorial:

Understand librosa.load() is Between -1.0 and 1.0 – Librosa Tutorial

Display sound amplitude using python matplotlib

Sound amplitude looks like:

Audio amplitude

You can get more information in this tutorial:

Understand Audio Amplitude and Power Spectrogram – Python Audio Processing

Here we will display it by matplotlib.

fig, ax = plt.subplots()
ax.plot(time,y)
ax.set(xlabel='Time(s)',ylabel='sound amplitude')
plt.show()

Run this code, we will see:

Display Sound Amplitude in Python: A Step Guide - Python Librosa Tutorial

Leave a Reply

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