首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >python代码报错KeyError:-1,请问如何解决?

python代码报错KeyError:-1,请问如何解决?

提问于 2024-04-27 01:33:46
回答 1关注 0查看 138

wavs = glob.glob('A2_103.wav')

print(wavs)

with open('dictionary.pkl', 'rb') as fr:

[char2id, id2char, mfcc_mean, mfcc_std] = pickle.load(fr)

mfcc_dim = 13

model = load_model('asr.h5')

index = np.random.randint(len(wavs))

print(wavs[index])

audio, sr = librosa.load(wavs[index])

energy = librosa.feature.rmse(audio)

frames = np.nonzero(energy >= np.max(energy) / 5)

indices = librosa.core.frames_to_samples(frames)[1]

audio = audio[indices[0]:indices[-1]] if indices.size else audio[0:0]

X_data = mfcc(audio, sr, numcep=mfcc_dim, nfft=551)

X_data = (X_data - mfcc_mean) / (mfcc_std + 1e-14)

print(X_data.shape)

pred = model.predict(np.expand_dims(X_data, axis=0))

pred_ids = K.eval(K.ctc_decode(pred, [X_data.shape[0]], greedy=False, beam_width=10, top_paths=1)[0][0])

pred_ids = pred_ids.flatten().tolist()

print(''.join([id2char[i] for i in pred_ids]))

运行这段代码之后报错

print(''.join([id2char[i] for i in pred_ids]))

KeyError: -1

请问该怎么解决呢

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档