Skip to content

Commit

Permalink
fix bugs and do some test
Browse files Browse the repository at this point in the history
  • Loading branch information
nl8590687 committed May 8, 2018
1 parent bf489b9 commit 08f7033
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ dataset
data_pinyin.txt

testClient.py

webapi/
14 changes: 9 additions & 5 deletions SpeechModel22.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def TestModel(self, datapath='', str_dataset='dev', data_count = 32, out_report
if(out_report == True):
txt_obj = open('Test_Report_' + str_dataset + '_' + nowtime + '.txt', 'w', encoding='UTF-8') # 打开文件并读入

txt = ''

for i in range(data_count):
data_input, data_labels = data.GetData((ran_num + i) % num_data) # 从随机数开始连续向后取一定数量数据
pre = self.Predict(data_input, data_input.shape[0] // 4)
Expand All @@ -221,16 +221,20 @@ def TestModel(self, datapath='', str_dataset='dev', data_count = 32, out_report
else: # 否则肯定是增加了一堆乱七八糟的奇奇怪怪的字
word_error_num += words_n # 就直接加句子本来的总字数就好了

if(i % 10 == 0):
print('测试进度:',i,'/',data_count)

txt = ''
if(out_report == True):
txt += str(i) + '\n'
txt += 'True:\t' + str(data_labels) + '\n'
txt += 'Pred:\t' + str(pre) + '\n'
txt += '\n'

txt_obj.write(txt)

print('*[测试结果] 语音识别 ' + str_dataset + ' 集语音单字错误率:', word_error_num / words_num * 100, '%')
if(out_report == True):
txt += '*[测试结果] 语音识别 ' + str_dataset + ' 集语音单字错误率: ' + str(word_error_num / words_num * 100) + ' %'
txt = '*[测试结果] 语音识别 ' + str_dataset + ' 集语音单字错误率: ' + str(word_error_num / words_num * 100) + ' %'
txt_obj.write(txt)
txt_obj.close()

Expand Down Expand Up @@ -381,9 +385,9 @@ def model(self):

ms = ModelSpeech(datapath)

#ms.LoadModel(modelpath + 'm22_2\\speech_model22_e_0_step_257000.model')
#ms.LoadModel(modelpath + 'm22_2\\1\\speech_model22_e_0_step_159000.model')
ms.TrainModel(datapath, epoch = 50, batch_size = 4, save_step = 500)
#ms.TestModel(datapath, str_dataset='test', data_count = 64, 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
12 changes: 10 additions & 2 deletions asrserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@author: nl8590687
语音识别API的HTTP服务器程序
尚未完成
"""
import http.server
import urllib
Expand Down Expand Up @@ -45,6 +44,7 @@ def do_POST(self):
token = ''
fs = 0
wavs = []
#type = 'wavfilebytes' # wavfilebytes or python-list

for line in datas_split:
[key, value]=line.split('=')
Expand All @@ -54,10 +54,15 @@ def do_POST(self):
fs = int(value)
elif('token' == key ):
token = value
#elif('type' == key):
# type = value
else:
print(key, value)

#if('python-list' == type):
r = self.recognize([wavs], fs)
#else:
# r = self.recognize_from_file('')

if(token == 'qwertasd'):
#buf = '成功\n'+'wavs:\n'+str(wavs)+'\nfs:\n'+str(fs)
Expand All @@ -74,7 +79,7 @@ def do_POST(self):


#buf = '<!DOCTYPE HTML> \n<html> \n<head>\n<title>Post page</title>\n</head> \n<body>Post Data:%s <br />Path:%s\n</body> \n</html>'%(datas,self.path)
buf = bytes(buf],encoding="utf-8")
buf = bytes(buf,encoding="utf-8")
self.wfile.write(buf)

def recognize(self, wavs, fs):
Expand All @@ -92,6 +97,9 @@ def recognize(self, wavs, fs):
return r
pass

def recognize_from_file(self, filename):
pass

def start_server(ip, port):
http_server = http.server.HTTPServer((ip, int(port)), TestHTTPHandle)
print('服务器已开启')
Expand Down
3 changes: 0 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@

#ms.TestModel(datapath, str_dataset='test', data_count = 64, out_report = True)
r = ms.RecognizeSpeech_FromFile('E:\语音数据集\ST-CMDS-20170001_1-OS\\20170001P00241I0052.wav')
#r = ms.RecognizeSpeech_FromFile('E:\\VS2015解决方案\\wav文件读写样例\\wav文件读写样例\\bin\\Debug\\1.wav')
#r = ms.RecognizeSpeech_FromFile('/home/nl/01.wav')
#r = ms.RecognizeSpeech_FromFile('C:\\Users\\nl\\Desktop\\01.wav')
#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

0 comments on commit 08f7033

Please sign in to comment.