python-3.x - ValueError:操作数无法与形状 > (400,2) (400,) 一起广播
问题描述
亲爱的问题:我正在使用 PLP 从 wav 中提取特征,执行后这个(Pyhton 3.6 -Anaconda Spyder)我在这行遇到错误
文件“C:\ProgramData\Anaconda3\lib\site-packages\sidekit\frontend\features.py”,第 399 行,在 power_spectrum ahan = framed[start:stop, :] * window
ValueError:操作数无法与形状一起广播 (400,2) (400,)
#!usr/bin/python
import numpy.matlib
import scipy
from scipy.fftpack.realtransforms import dct
from sidekit.frontend.vad import pre_emphasis
from sidekit.frontend.io import *
from sidekit.frontend.normfeat import *
from sidekit.frontend.features import *
import scipy.io.wavfile as wav
import numpy as np
def readWavFile(wav):
#given a path from the keyboard to read a .wav file
#wav = raw_input('Give me the path of the .wav file you want to read: ')
inputWav = 'C:/Speech_Processing/2-Speech_Signal_Processing_and_Classification-master/feature_extraction_techniques'+wav
return inputWav
#reading the .wav file (signal file) and extract the information we need
def initialize(inputWav):
rate , signal = wav.read(readWavFile(inputWav)) # returns a wave_read object , rate: sampling frequency
sig = wave.open(readWavFile(inputWav))
# signal is the numpy 2D array with the date of the .wav file
# len(signal) number of samples
sampwidth = sig.getsampwidth()
print ('The sample rate of the audio is: ',rate)
print ('Sampwidth: ',sampwidth)
return signal , rate
def PLP():
folder = input('Give the name of the folder that you want to read data: ')
amount = input('Give the number of samples in the specific folder: ')
for x in range(1,int(amount)+1):
wav = '/'+folder+'/'+str(x)+'.wav'
print (wav)
#inputWav = readWavFile(wav)
signal,rate = initialize(wav)
#returns PLP coefficients for every frame
plp_features = plp(signal,rasta=True)
meanFeatures(plp_features[0])
#compute the mean features for one .wav file (take the features for every frame and make a mean for the sample)
def meanFeatures(plp_features):
#make a numpy array with length the number of plp features
mean_features=np.zeros(len(plp_features[0]))
#for one input take the sum of all frames in a specific feature and divide them with the number of frames
for x in range(len(plp_features)):
for y in range(len(plp_features[x])):
mean_features[y]+=plp_features[x][y]
mean_features = (mean_features / len(plp_features))
print (mean_features)
def main():
PLP()
main()
解决方案
推荐阅读
- django - 对象在 Django Rest Framework 中没有属性
- azure - Azure DSC 将文件从存储上传到 VM?
- java - Springboot应用程序中出现意外的whitelabel错误404
- typescript - 无法在方法中访问离子构造函数参数
- ios - 为什么这个 iOS 项目不使用 XCode 11 构建?
- laravel - 我想使用 Laravel 在图表 js 上显示项目名称和时间
- spring - 在春季卡夫卡中面临“AddOffsetsToTxnResponse 中的意外错误”问题
- python - Databricks - 在 python 控制台中运行创建替换视图
- python - Python 测试入门
- c# - XAML 热重载不适用于自定义生成配置