Last active
January 9, 2020 07:17
-
-
Save hasithsura/78a1fb909a4271d6287c3b273038177f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
import librosa | |
def get_melspectrogram_db(file_path, sr=None, n_fft=2048, hop_length=512, n_mels=128, fmin=20, fmax=8300, top_db=80): | |
wav,sr = librosa.load(file_path,sr=sr) | |
if wav.shape[0]<5*sr: | |
wav=np.pad(wav,int(np.ceil((5*sr-wav.shape[0])/2)),mode='reflect') | |
else: | |
wav=wav[:5*sr] | |
spec=librosa.feature.melspectrogram(wav, sr=sr, n_fft=n_fft, | |
hop_length=hop_length,n_mels=n_mels,fmin=fmin,fmax=fmax) | |
spec_db=librosa.power_to_db(spec,top_db=top_db) | |
return spec_db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment