資源簡介
ASR_CNN.zip
代碼片段和文件信息
#!/usr/bin/env?python3
#?-*-?coding:?utf-8?-*-
“““
語音識別API的HTTP服務器程序
“““
import?os
import?http.server
import?urllib
import?keras
from?SpeechModel?import?ModelSpeech
from?LanguageModel?import?ModelLanguage
import?platform?as?plat
from?package?import?pinyin2hanzi
root?=?‘D:/SpeechRecognition‘???????????????#根目錄
num2pyyin_dict?=?pinyin2hanzi.get_num2pyyin_dict(os.path.join(root‘package/resource/num2pinyin.txt‘))
hangban_com_name_dict?=?pinyin2hanzi.make_tone_file(os.path.join(root‘package/resource/hb_name.txt‘)?num2pyyin_dict)
hangban_num_dict?=?pinyin2hanzi.make_tone_file(os.path.join(root‘package/resource/hb_num.txt‘)?num2pyyin_dict)
command_dict?=?pinyin2hanzi.make_tone_file(os.path.join(root‘package/resource/cmd.txt‘)?num2pyyin_dict)
modelpath?=?‘model_speech‘??????????#文件夾的名字
system_type?=?plat.system()????????????#操作系統的類型
if(system_type?==?‘Windows‘):
datapath?=?‘D:\\語音數據集‘
modelpath?=?modelpath?+?‘\\‘
elif(system_type?==?‘Linux‘):
datapath?=?‘dataset‘
modelpath?=?modelpath?+?‘/‘
else:
print(‘*[Message]?Unknown?System\n‘)
datapath?=?‘dataset‘
modelpath?=?modelpath?+?‘/‘
ms?=?ModelSpeech(datapath)
ms.LoadModel(modelpath?+?‘speech_model251_e_0_step_625000.model‘)
class?TestHTTPHandle(http.server.baseHTTPRequestHandler):??
def?setup(self):
self.request.settimeout(10)
http.server.baseHTTPRequestHandler.setup(self)
def?_set_response(self):
self.send_response(200)
self.send_header(‘Content-type‘?‘text/html‘)
self.end_headers()
def?do_GET(self):??
buf?=?‘ASRT_SpeechRecognition?API‘??
self.protocal_version?=?‘HTTP/1.1‘???
self._set_response()
buf?=?bytes(bufencoding=“utf-8“)
self.wfile.write(buf)?
def?do_POST(self):??
path?=?self.path??
print(path)
datas?=?self.rfile.read(int(self.headers[‘content-length‘]))
datas?=?datas.decode(‘utf-8‘)
datas_split?=?datas.split(‘&‘)
token?=?‘‘
fs?=?0
wavs?=?[]
for?line?in?datas_split:
[key?value]=line.split(‘=‘)
if(‘wavs‘?==?key?and?‘‘?!=?value):
wavs.append(int(value))
elif(‘fs‘?==?key):
fs?=?int(value)
elif(‘token‘?==?key?):
token?=?value
else:
print(key?value)
if(token?!=?‘qwertasd‘):
buf?=?‘403‘
print(buf)
buf?=?bytes(bufencoding=“utf-8“)
self.wfile.write(buf)??
return
if(len(wavs)>0):
r?=?self.recognize([wavs]?fs)
else:
r?=?‘‘
if(token?==?‘qwertasd‘):
buf?=?r
else:
buf?=?‘403‘
self._set_response()
print(buf)
buf?=?bytes(bufencoding=“utf-8“)
self.wfile.write(buf)??
def?recognize(self?wavs?fs):
r=‘‘
try:
r_speech?=?ms.RecognizeSpeech(wavs?fs)
result?=?pinyin2hanzi.get_result(hangban_com_name_dict?hangban_num_dict?command_dict?r_speech)
print(result)
final_result?=?result[0][0]+‘?‘+result[1][0]+‘?‘+result[2][0]
except:
r=‘‘
print(‘[*Message]?Server?raise?a?bug.?‘)
return?final_result
pass
def?recognize_from_file(self?filename):
pass
import?socket
class?HTTPServerV6(http.server.HTTPServer):
addre
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-08-01?23:18??ASR_CNN\
?????目錄???????????0??2020-08-01?23:18??ASR_CNN\.idea\
?????文件???????22437??2019-09-25?15:50??ASR_CNN\.idea\dbnavigator.xm
?????文件?????????240??2020-02-06?17:07??ASR_CNN\.idea\encodings.xm
?????目錄???????????0??2020-08-01?20:48??ASR_CNN\.idea\inspectionProfiles\
?????文件?????????174??2019-09-24?18:07??ASR_CNN\.idea\inspectionProfiles\profiles_settings.xm
?????文件?????????215??2020-08-01?21:32??ASR_CNN\.idea\misc.xm
?????文件?????????293??2019-09-24?18:07??ASR_CNN\.idea\modules.xm
?????文件?????????239??2020-02-03?09:00??ASR_CNN\.idea\other.xm
?????文件?????????465??2020-08-01?21:32??ASR_CNN\.idea\SpeechRecognition.iml
?????文件???????28334??2020-08-01?23:18??ASR_CNN\.idea\workspace.xm
?????文件????????3597??2019-09-29?20:26??ASR_CNN\asrserver.py
?????文件?????????413??2019-10-02?21:40??ASR_CNN\Client.py
?????文件???????10530??2020-08-01?19:21??ASR_CNN\data.syllable.txt
?????文件????????1494??2020-08-01?19:20??ASR_CNN\data.wav.txt
?????文件???????32747??2020-02-06?18:48??ASR_CNN\dict.txt
?????目錄???????????0??2020-08-01?23:17??ASR_CNN\general_function\
?????目錄???????????0??2020-08-01?20:48??ASR_CNN\general_function\b\
?????文件?????????261??2019-09-28?11:03??ASR_CNN\general_function\b\dict.txt
?????文件?????????261??2019-09-28?11:03??ASR_CNN\general_function\dict.txt
?????文件?????????979??2020-08-01?23:17??ASR_CNN\general_function\file_dict.py
?????文件????????3155??2020-08-01?23:17??ASR_CNN\general_function\file_wav.py
?????文件?????????487??2020-08-01?23:17??ASR_CNN\general_function\gen_func.py
?????文件????????3249??2020-08-01?23:17??ASR_CNN\general_function\muti_gpu.py
?????文件??????126764??2019-09-19?12:35??ASR_CNN\general_function\test1.wav
?????文件?????????168??2020-08-01?23:17??ASR_CNN\general_function\__init__.py
?????目錄???????????0??2020-08-01?23:17??ASR_CNN\general_function\__pycache__\
?????文件????????1479??2019-09-09?18:43??ASR_CNN\general_function\__pycache__\file_dict.cpython-35.pyc
?????文件????????1092??2020-08-01?23:17??ASR_CNN\general_function\__pycache__\file_dict.cpython-37.pyc
?????文件????????6888??2019-09-09?18:39??ASR_CNN\general_function\__pycache__\file_wav.cpython-35.pyc
?????文件????????3010??2020-08-01?23:17??ASR_CNN\general_function\__pycache__\file_wav.cpython-37.pyc
............此處省略153個文件信息
評論
共有 條評論