Librosa

0.11.0 · active · verified Thu Apr 09

Librosa is a Python module for audio and music processing, providing a wide array of tools for analysis, feature extraction, and manipulation of audio signals. The current version is 0.11.0, with regular updates that typically include bug fixes, performance improvements, and minor feature enhancements, aiming for stable releases every few months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate a dummy audio signal (or load a real one), compute Mel-frequency cepstral coefficients (MFCCs), and visualize them using `librosa.display` and `matplotlib`. Remember to replace the dummy signal with `librosa.load` for actual audio files.

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

# Generate a dummy audio signal for demonstration (5 seconds of random noise)
sr = 22050 # sample rate
duration = 5 # seconds
y = np.random.randn(int(sr * duration))

# In a real application, you'd load an audio file:
# y, sr = librosa.load("path/to/your/audio.wav", sr=None) # Use sr=None to preserve original sample rate

# Compute Mel-frequency cepstral coefficients (MFCCs)
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)

# Display the MFCCs
plt.figure(figsize=(10, 4))
librosa.display.specshow(mfccs, x_axis='time', sr=sr, cmap='viridis')
plt.colorbar()
plt.title('MFCC (Mel-frequency cepstral coefficients)')
plt.tight_layout()
# plt.show() # Uncomment to display the plot
print(f"MFCCs shape: {mfccs.shape}")

view raw JSON →