"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

February 17, 2019

Day #213 - Working with Sound and Python


#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)
view raw sound.py hosted with ❤ by GitHub
Happy Mastering DL!!!

No comments: