This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pip install librosa | |
import librosa | |
import matplotlib.pyplot as plt | |
import librosa.display | |
import numpy as np | |
path = r'D:\PetProject\Audio_Analytics\UrbanSound.tar\UrbanSound\data\air_conditioner\204240.wav' | |
#waveform `y` | |
#Store the sampling rate as `sr` | |
#By default, this uses resampy’s high-quality mode (‘kaiser_best’). | |
y,sr = librosa.load(path,res_type='kaiser_fast') | |
plt.figure(figsize=(10,5)) | |
librosa.display.waveplot(y,sr=sr) | |
#Mel frequency cepstral coefficients (MFCCs) | |
#small set of features | |
mfcc = librosa.feature.mfcc(y=y, sr=sr) | |
print(mfcc.shape) | |
#numpy.ndarray of size (n_mfcc, T) | |
mfccs=np.mean(librosa.feature.mfcc(y=y,sr=sr,n_mfcc=40).T,axis=0) | |
print(mfccs) | |
print(mfccs.shape) | |
#Load 5 seconds of a wav file, starting 15 seconds in | |
y,sr = librosa.load(path,res_type='kaiser_fast', offset=15.0, duration=5.0) | |
plt.figure(figsize=(10,5)) | |
librosa.display.waveplot(y,sr=sr) | |
#Load a wav file and resample to 11 KHz | |
y,sr = librosa.load(path,res_type='kaiser_fast',sr=11025) | |
plt.figure(figsize=(10,5)) | |
librosa.display.waveplot(y,sr=sr) |
No comments:
Post a Comment