Skip to content

Commit

Permalink
修复了识别成汉字时有时候识别不全的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nl8590687 committed May 28, 2018
1 parent d0b76f6 commit caefbc8
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 22 deletions.
15 changes: 13 additions & 2 deletions LanguageModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,32 @@ def SpeechToText(self, list_syllable):
if(length == 0): # 传入的参数没有包含任何拼音时
return ''

# 先取出一个字,即拼音列表中第一个字
str_tmp = [list_syllable[0]]

for i in range(0, length - 1):
# 依次从第一个字开始每次连续取两个字拼音
str_split = list_syllable[i] + ' ' + list_syllable[i+1]
#print(str_split,str_tmp,r)
# 如果这个拼音在汉语拼音状态转移字典里的话
if(str_split in self.pinyin):
# 将第二个字的拼音加入
str_tmp.append(list_syllable[i+1])
else:
# 否则不加入,然后直接将现有的拼音序列进行解码
str_decode = self.decode(str_tmp, 0.0000)
#print('decode ',str_tmp,str_decode)
if(str_decode != []):
r += str_decode[0][0]
# 再重新从i+1开始作为第一个拼音
str_tmp = [list_syllable[i+1]]


#print(str_tmp)
#print('最后:', str_tmp)
str_decode = self.decode(str_tmp, 0.0000)

#print('剩余解码:',str_decode)

if(str_decode != []):
r += str_decode[0][0]

Expand Down Expand Up @@ -208,7 +219,7 @@ def GetPinyin(self, filename):

list_pinyin=pinyin_split[0]

if(list_pinyin not in dic):
if(list_pinyin not in dic and int(pinyin_split[1]) > 1):
dic[list_pinyin] = pinyin_split[1]
return dic

Expand Down
4 changes: 2 additions & 2 deletions SpeechModel24.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ def model(self):

ms = ModelSpeech(datapath)

ms.LoadModel(modelpath + 'm24\\speech_model24_e_0_step_112500.model')
ms.LoadModel(modelpath + 'm24\\speech_model24_e_0_step_411000.model')
#ms.TrainModel(datapath, epoch = 50, batch_size = 4, save_step = 500)
ms.TestModel(datapath, str_dataset='test', data_count = 128, out_report = True)
#ms.TestModel(datapath, str_dataset='test', data_count = 128, out_report = True)
#r = ms.RecognizeSpeech_FromFile('E:\\语音数据集\\ST-CMDS-20170001_1-OS\\20170001P00241I0053.wav')
#r = ms.RecognizeSpeech_FromFile('E:\\语音数据集\\ST-CMDS-20170001_1-OS\\20170001P00020I0087.wav')
#r = ms.RecognizeSpeech_FromFile('E:\\语音数据集\\wav\\train\\A11\\A11_167.WAV')
Expand Down
7 changes: 4 additions & 3 deletions SpeechModel25.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def CreateModel(self):

model = Model(inputs=[input_data, labels, input_length, label_length], outputs=loss_out)

model.summary()
#model.summary()

# clipnorm seems to speeds up convergence
#sgd = SGD(lr=0.0001, decay=1e-6, momentum=0.9, nesterov=True, clipnorm=5)
Expand Down Expand Up @@ -403,8 +403,9 @@ def model(self):

ms = ModelSpeech(datapath)

#ms.LoadModel(modelpath + 'm25\\speech_model25_e_0_step_1.model')
ms.TrainModel(datapath, epoch = 50, batch_size = 4, save_step = 500)
# 全场最佳 speech_model25_e_0_step_340000
ms.LoadModel(modelpath + 'm25\\speech_model25_e_0_step_382000.model')
#ms.TrainModel(datapath, epoch = 50, batch_size = 4, save_step = 500)
#ms.TestModel(datapath, str_dataset='test', data_count = 128, out_report = True)
#r = ms.RecognizeSpeech_FromFile('E:\\语音数据集\\ST-CMDS-20170001_1-OS\\20170001P00241I0053.wav')
#r = ms.RecognizeSpeech_FromFile('E:\\语音数据集\\ST-CMDS-20170001_1-OS\\20170001P00020I0087.wav')
Expand Down
Loading

0 comments on commit caefbc8

Please sign in to comment.