From a2588dec1af02e106a910286c692354ca4fe626a Mon Sep 17 00:00:00 2001 From: nl8590687 <3210346136@qq.com> Date: Thu, 7 Jun 2018 12:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=9A=84=E6=A6=82=E7=8E=87=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84Bug=EF=BC=8C=E5=B9=B6=E6=8F=90?= =?UTF-8?q?=E9=AB=98API=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LanguageModel.py | 4 +++- asrserver.py | 30 +++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/LanguageModel.py b/LanguageModel.py index 48eba22..0b4774e 100644 --- a/LanguageModel.py +++ b/LanguageModel.py @@ -137,8 +137,9 @@ class ModelLanguage(): # 语音模型类 #print('tmp_words: ',tmp_words,tmp_words in self.model2) if(tmp_words in self.model2): # 判断它们是不是再状态转移表里 #print(tmp_words,tmp_words in self.model2) - tuple_word[1] = tuple_word[1] * float(self.model2[tmp_words]) / float(self.model1[tmp_words[-1]]) + tuple_word[1] = tuple_word[1] * float(self.model2[tmp_words]) / float(self.model1[tmp_words[-2]]) # 核心!在当前概率上乘转移概率,公式化简后为第n-1和n个字出现的次数除以第n-1个字出现的次数 + #print(self.model2[tmp_words],self.model1[tmp_words[-2]]) else: tuple_word[1] = 0.0 continue @@ -238,6 +239,7 @@ if(__name__=='__main__'): #str_pinyin = ['wo3','qu4','a4','mei2','shi4','er2','la1'] #str_pinyin = ['wo3', 'men5', 'qun2', 'li3', 'xiong1', 'di4', 'jian4', 'mei4', 'dou1', 'zai4', 'shuo1'] #str_pinyin = ['su1', 'an1', 'ni3', 'sui4', 'li4', 'yun4', 'sui2', 'cong2', 'jiao4', 'ming2', 'tao2', 'qi3', 'yu2', 'peng2', 'ya4', 'yang4', 'chao1', 'dao3', 'jiang1', 'li3', 'yuan2', 'kang1', 'zhua1', 'zou3'] + str_pinyin = ['da4', 'jia1', 'hao3'] #r = ml.decode(str_pinyin) r=ml.SpeechToText(str_pinyin) print('语音转文字结果:\n',r) diff --git a/asrserver.py b/asrserver.py index 180388c..c3fea57 100644 --- a/asrserver.py +++ b/asrserver.py @@ -14,7 +14,7 @@ from LanguageModel import ModelLanguage datapath = 'data/' modelpath = 'model_speech/' ms = ModelSpeech(datapath) -ms.LoadModel(modelpath + 'speech_model24_e_0_step_216500.model') +ms.LoadModel(modelpath + 'm24/speech_model24_e_0_step_411000.model') ml = ModelLanguage('model_language') ml.LoadModel() @@ -55,7 +55,7 @@ class TestHTTPHandle(http.server.BaseHTTPRequestHandler): for line in datas_split: [key, value]=line.split('=') - if('wavs' == key): + if('wavs' == key and '' != value): wavs.append(int(value)) elif('fs' == key): fs = int(value) @@ -66,8 +66,18 @@ class TestHTTPHandle(http.server.BaseHTTPRequestHandler): else: print(key, value) + if(token != 'qwertasd'): + buf = '403' + print(buf) + buf = bytes(buf,encoding="utf-8") + self.wfile.write(buf) + return + #if('python-list' == type): - r = self.recognize([wavs], fs) + if(len(wavs)>0): + r = self.recognize([wavs], fs) + else: + r = '' #else: # r = self.recognize_from_file('') @@ -82,14 +92,20 @@ class TestHTTPHandle(http.server.BaseHTTPRequestHandler): self._set_response() #buf = ' \n \n
\n