首页 > 解决方案 > 如何在 Python 3 中比较和可视化两个 .wav 文件?

问题描述

我在 Jupyter 上使用 Python 3,我试图找出音频文件(有一些噪音)与没有原始文件的准确性。请在下面找到我在网上找到的代码,

import librosa
import matplotlib.pyplot as plt
from dtw import dtw

#Loading audio files
y1, sr1 = librosa.load('data/dev1_female3_liverec_130ms_1m_sim_1.wav') 
y2, sr2 = librosa.load('data/dev1_female3_liverec_130ms_1m_sim_1o.wav') 

#Showing multiple plots using subplot
plt.subplot(1, 2, 1) 
mfcc1 = librosa.feature.mfcc(y1,sr1)   #Computing MFCC values
librosa.display.specshow(mfcc1)

plt.subplot(1, 2, 2)
mfcc2 = librosa.feature.mfcc(y2, sr2)
librosa.display.specshow(mfcc2)

dist, cost, path = dtw(mfcc1.T, mfcc2.T)
print("The normalized distance between the two : ",dist)   # 0 for similar audios 

plt.imshow(cost.T, origin='lower', cmap=plt.get_cmap('gray'), interpolation='nearest')
plt.plot(path[0], path[1], 'w')   #creating plot for DTW

plt.show()

我收到一个错误“找不到模块名称 librosa”

标签: python-3.xaudio-comparison

解决方案


首先你必须安装 librosa ,如果你使用的是 python 的 anaconda 发行版,那么在 anaconda 提示符下运行pip install librosa或者运行你的 CMD 。

其次import librosa在 jupyter 上然后开始工作。


推荐阅读