ValueError:操作数不能与形状(83,10)(7,)一起广播

时间:2019-03-16 12:11:39

标签: python scipy speech-recognition

此行中的错误

 ps_test = [m.transform(observation) for m in ms]

代码(部分)

transform funciton-
def transform(self, obs):
if len(obs.shape) == 2:
            B = self._state_likelihood(obs)
            log_likelihood, _ = self._forward(B)
            return log_likelihood
        elif len(obs.shape) == 3:
            count = obs.shape[0]
            out = np.zeros((count,))
            for n in range(count):
                B = self._state_likelihood(obs[n, :, :])
                log_likelihood, _ = self._forward(B)
                out[n] = log_likelihood
            return out

本部分中的错误-

new_data = np.zeros(9600)
maxsize = 755260
_, new_d = wavfile.read(r"C:\Users\Kanika Bansalwal\AppData\Local\Programs\Python\Python36\audio1\apple\apple01.wav")
print(new_d.shape[0])
new_data = np.zeros(new_d.shape[0])
new_data[:new_d.shape[0]] = new_d

new_data = new_data[:maxsize]

observation = []

new_d = np.abs(stft(new_data))
n_dim = 10
new_obs = np.zeros((n_dim, new_d.shape[0]))
for r in range(new_d.shape[0]):
    _, t = peakfind(new_d[r, :], n_peaks=n_dim)
    new_obs[:, r] = t.copy()
observation.append(new_obs)

observation = np.atleast_3d(observation)
observation /= observation.sum(axis=1)
**ps_test = [m.transform(observation) for m in ms]**
res_test = np.vstack(ps_test)
test_predicted_label = np.argmax(res_test, axis=0)
word_spoken = dictionary[test_predicted_label]
print (word_spoken)

整个代码链接:https://github.com/prakashpandey9/IsolatedSpeechRecognition/blob/master/Isolated_Speech_Recognition.py

0 个答案:

没有答案