我在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”
3条答案
按热度按时间sbtkgmzw1#
首先你必须安装librosa,如果你使用的是anaconda发行版的python,那么在anaconda提示符下运行
pip install librosa
或者运行你的CMD。其次jupyter上的
import librosa
,然后开始工作。ibrsph3r2#
安装librosa lib后,它在librosa.display上给予问题,因此请将librosa.display导入为dis并使用。另外,它将在dtw(mfcc1.T,mfcc2.T)行上出现问题。有关此问题,请参阅以下内容
2o7dmzc53#
.....故障排除
请检查python环境是否为项目代码对应的python环境
使用命令"pip list"
如果你没有看到librosa,用"pip install librosa"命令安装它。
... Bug我运行您的代码并得到一个错误:
TypeError:无法解包不可迭代的DTW对象
.....更多错误消息:
(venv_比较_两个_音频)20230111 17:57:56比较_两个_音频$/用户/xxx/选项/迷你视频3/环境/venv_比较_两个_音频/bin/python3.10/用户/xxx/迷你应用程序/比较_两个_音频/比较_两个_音频. py
/用户/xxx/迷你应用程序/比较两个音频/比较两个音频. py:14:未来警告:将y =[0.0.0...0.0.0.],sr = 22050作为关键字参数传递。从版本0.10开始,将这些参数作为位置参数传递将导致错误
/用户/xxx/迷你应用程序/比较两个音频/比较两个音频. py:18:未来警告:将y =[0.0.0...0.0.0.],sr = 22050作为关键字参数传递。从版本0.10开始,将这些参数作为位置参数传递将导致错误
追溯(最近调用最后调用):
文件"/用户/xxx/迷你应用程序/比较两个音频/比较两个音频. py ",第21行,位于
TypeError:无法解包不可迭代的DTW对象
(venv比较两个音频)20230111 17:58:02比较两个音频$
.....代码:
..... Python环境