0% found this document useful (0 votes)
8 views5 pages

Audio Feature Extraction with Python

Uploaded by

rohitm04122002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Audio Feature Extraction with Python

Uploaded by

rohitm04122002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AIM:- Audio Signal Feature Extrac on

Objec ve:

To extract and analyze the following features from an audio signal:

1. Energy

2. Root Mean Square (RMS) Energy

3. Zero Crossing Rate

4. Spectrogram

5. Mel Spectrogram

6. Mel-Frequency Cepstral Coefficients (MFCCs)

7. Spectral Centroid

8. Spectral Roll-off

9. Spectral Bandwidth

Theory:-

Audio feature extrac on involves processing audio signals to extract relevant characteris cs for various a
pplica ons, such as speech recogni on, music classifica on, and emo on detec on. This lab report detai
ls the extrac on of fundamental audio features using Python.

Source Code:

import librosa

import numpy as np

import [Link] as plt

# Load audio file

file_path = 'path_to_audio_fi[Link]'

y, sr = [Link](file_path)

# Extrac ng Features

# 1. Energy

energy = [Link](y**2)
print("Energy:", energy)

# 2. Root Mean Square (RMS) Energy

rms = [Link](y=y)[0]

print("RMS Energy:", rms)

# 3. Zero Crossing Rate

zero_crossings = [Link].zero_crossing_rate(y)[0]

print("Zero Crossing Rate:", zero_crossings)

# 4. Spectrogram

spectrogram = [Link](librosa.s t(y))

print("Spectrogram Shape:", [Link])

# 5. Mel Spectrogram

mel_spectrogram = [Link](y=y, sr=sr)

print("Mel Spectrogram Shape:", mel_spectrogram.shape)

# 6. MFCC

mfcc = [Link](y=y, sr=sr, n_mfcc=13)

print("MFCC Shape:", [Link])

# 7. Spectral Centroid

spectral_centroid = [Link].spectral_centroid(y=y, sr=sr)[0]

print("Spectral Centroid:", spectral_centroid)

# 8. Spectral Roll-off

spectral_rolloff = [Link].spectral_rolloff(y=y, sr=sr)[0]

print("Spectral Roll-off:", spectral_rolloff)


# 9. Spectral Bandwidth

spectral_bandwidth = [Link].spectral_bandwidth(y=y, sr=sr)[0]

print("Spectral Bandwidth:", spectral_bandwidth)

# Plo ng the extracted features

plt.figure(figsize=(14, 10))

# Plot RMS Energy

[Link](3, 3, 1)

[Link](rms)

plt. tle('RMS Energy')

# Plot Zero Crossing Rate

[Link](3, 3, 2)

[Link](zero_crossings)

plt. tle('Zero Crossing Rate')

# Plot Spectrogram

[Link](3, 3, 3)

[Link](librosa.amplitude_to_db(spectrogram, ref=[Link]), sr=sr, x_axis=' me',


y_axis='log')

[Link](format='%+2.0f dB')

plt. tle('Spectrogram')

# Plot Mel Spectrogram

[Link](3, 3, 4)
[Link](librosa.power_to_db(mel_spectrogram, ref=[Link]), sr=sr, x_axis=' me',
y_axis='mel')

[Link](format='%+2.0f dB')

plt. tle('Mel Spectrogram')

# Plot MFCC

[Link](3, 3, 5)

[Link](mfcc, sr=sr, x_axis=' me')

[Link]()

plt. tle('MFCC')

# Plot Spectral Centroid

[Link](3, 3, 6)

[Link](spectral_centroid.T, label='Spectral Centroid')

[Link]('Frames')

[Link]('Hz')

plt. tle('Spectral Centroid')

# Plot Spectral Roll-off

[Link](3, 3, 7)

[Link](spectral_rolloff.T, label='Spectral Roll-off')

[Link]('Frames')

[Link]('Hz')

plt. tle('Spectral Roll-off')

# Plot Spectral Bandwidth

[Link](3, 3, 8)

[Link](spectral_bandwidth.T, label='Spectral Bandwidth')

[Link]('Frames')
[Link]('Hz')

plt. tle('Spectral Bandwidth')

plt. ght_layout()

[Link]()

Conclusion:

This lab successfully demonstrated the extrac on of various audio features using the librosa library in Pyt
hon. Each feature provides unique insights into the characteris cs of the audio signal, contribu ng to var
ious applica ons in audio analysis and machine learning. By visualizing these features, we gain a deeper
understanding of the audio content, enabling more informed decisions in subsequent processing tasks.

You might also like