├── README.md └── mfcc.py /README.md: -------------------------------------------------------------------------------- 1 | # comparing-audio-files-python 2 | This project is for the comparison of two audio files based on their MFCC's. 3 | 4 | 5 | Please feel free to submit a PR with commented code (if needed). 6 | -------------------------------------------------------------------------------- /mfcc.py: -------------------------------------------------------------------------------- 1 | import librosa 2 | import matplotlib.pyplot as plt 3 | from dtw import dtw 4 | 5 | #Loading audio files 6 | y1, sr1 = librosa.load('/home/user/Desktop/1.wav') 7 | y2, sr2 = librosa.load('/home/user/Desktop/2.wav') 8 | 9 | #Showing multiple plots using subplot 10 | plt.subplot(1, 2, 1) 11 | mfcc1 = librosa.feature.mfcc(y1,sr1) #Computing MFCC values 12 | librosa.display.specshow(mfcc1) 13 | 14 | plt.subplot(1, 2, 2) 15 | mfcc2 = librosa.feature.mfcc(y2, sr2) 16 | librosa.display.specshow(mfcc2) 17 | 18 | dist, cost, path = dtw(mfcc1.T, mfcc2.T) 19 | print("The normalized distance between the two : ",dist) # 0 for similar audios 20 | 21 | plt.imshow(cost.T, origin='lower', cmap=plt.get_cmap('gray'), interpolation='nearest') 22 | plt.plot(path[0], path[1], 'w') #creating plot for DTW 23 | 24 | plt.show() #To display the plots graphically 25 | --------------------------------------------------------------------------------