def get_wav_mfcc(wav_path):#(wav_path)
y,sr = librosa.load(wav_path)
wav_feature = mfcc( y, sr, numcep=13, winlen=0.025, winstep=0.01,
nfilt=26, nfft=1024, lowfreq=0, highfreq=None, preemph=0.97)
print(wav_feature.shape)
输出:由于自己音频有的市场不同,所以shape有(80,13)、(99,13)(122,13)等
total_mfcc = []
d_mfcc_feat = delta(wav_feature, 1)
print('一阶差分mfcc:', d_mfcc_feat.shape)
输出:shape同上:(80,13)、(99,13)(122 ,13)等
d_mfcc_feat2 = delta(wav_feature, 2)
print('二阶差分mfcc:', d_mfcc_feat2.shape)
输出:shape同上:(80,13)、(99,13)(122,13)等
feature = np.hstack((wav_feature, d_mfcc_feat, d_mfcc_feat2))
print(feature.shape)
输出:shape:(80,39)(99,39)(122,39)等
total_mfcc.extend(feature)
total_mfcc = np.array(total_mfcc)
print(total_mfcc)
输出:(80,39)(99,39)(122,39)等形式的矩阵
最终想要实现,通过补0或者其他方式,使得输出的矩阵统一成(99,39),需要接下来加些什么代 码??????
下面是本人代码,想补0,没有成功
data = list(np.array( total_mfcc))
print('list:',data)#根据整个输出
while len(data)>122:#修改此数值
del data[len(waveData[0])-1]
del data[0]
# print(len(data))
while len(data)<122:
data.append(0)
print('add0:',data)
data=np.array(data)
return data
你的矩阵是numpy 格式吧。用这个函数试试?这个是我的例子
d1=np.array([[1,2,3,4,5,1],[1,2,3,4,5,2],[1,2,3,4,5,3],[1,2,3,4,5,4],[1,2,3,4,5,5],[1,2,3,4,5,6],[1,2,3,4,5,7],[1,2,3,4,5,8]])
d2=np.array([[1,2,3,4,5,1],[1,2,3,4,5,2],[1,2,3,4,5,3]])
print("原始:")
print(d1)
print(d2)
def reshape(d):
m,n=d.shape
if m>=5:
return d[0:5,:]
else:
return np.row_stack((d,[[0]*n]*(5-m)))
d1=reshape(d1)
d2=reshape(d2)
print("转换后:")
print(d1)
print(d2)
先谢啦,我试下哈
可以了 感谢
可以了 感谢