2018-04-25 19:50:32 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2021-05-16 19:44:05 +08:00
|
|
|
#
|
|
|
|
# Copyright 2016-2099 Ailemon.net
|
|
|
|
#
|
|
|
|
# This file is part of ASRT Speech Recognition Tool.
|
|
|
|
#
|
|
|
|
# ASRT is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
# ASRT is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with ASRT. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
# ============================================================================
|
|
|
|
|
2018-04-25 19:50:32 +08:00
|
|
|
"""
|
|
|
|
@author: nl8590687
|
|
|
|
用于测试整个一套语音识别系统的程序
|
|
|
|
语音模型 + 语言模型
|
|
|
|
"""
|
|
|
|
import platform as plat
|
|
|
|
|
2019-01-04 15:38:20 +08:00
|
|
|
from SpeechModel251 import ModelSpeech
|
2019-03-29 14:28:01 +08:00
|
|
|
from LanguageModel2 import ModelLanguage
|
2021-05-16 20:53:23 +08:00
|
|
|
from tensorflow.keras import backend as K
|
2018-04-25 19:50:32 +08:00
|
|
|
|
|
|
|
datapath = ''
|
|
|
|
modelpath = 'model_speech'
|
|
|
|
|
|
|
|
system_type = plat.system() # 由于不同的系统的文件路径表示不一样,需要进行判断
|
|
|
|
if(system_type == 'Windows'):
|
2021-05-16 19:44:05 +08:00
|
|
|
datapath = 'Z:\\SpeechData'
|
2018-04-25 19:50:32 +08:00
|
|
|
modelpath = modelpath + '\\'
|
|
|
|
elif(system_type == 'Linux'):
|
|
|
|
datapath = 'dataset'
|
|
|
|
modelpath = modelpath + '/'
|
|
|
|
else:
|
|
|
|
print('*[Message] Unknown System\n')
|
|
|
|
datapath = 'dataset'
|
|
|
|
modelpath = modelpath + '/'
|
|
|
|
|
|
|
|
ms = ModelSpeech(datapath)
|
|
|
|
|
2018-05-05 13:41:45 +08:00
|
|
|
#ms.LoadModel(modelpath + 'm22_2\\0\\speech_model22_e_0_step_257000.model')
|
2021-05-16 19:44:05 +08:00
|
|
|
ms.LoadModel(modelpath + 'm251\\speech_model251_e_0_step_625000.model')
|
2018-04-25 19:50:32 +08:00
|
|
|
|
|
|
|
#ms.TestModel(datapath, str_dataset='test', data_count = 64, out_report = True)
|
2019-01-19 11:27:57 +08:00
|
|
|
r = ms.RecognizeSpeech_FromFile('D:\\语音数据集\\ST-CMDS-20170001_1-OS\\20170001P00241I0052.wav')
|
2019-03-29 14:28:01 +08:00
|
|
|
#r = ms.RecognizeSpeech_FromFile('D:\语音数据集\ST-CMDS-20170001_1-OS\\20170001P00241I0053.wav')
|
|
|
|
#r = ms.RecognizeSpeech_FromFile('D:\\语音数据集\\ST-CMDS-20170001_1-OS\\20170001P00020I0087.wav')
|
|
|
|
#r = ms.RecognizeSpeech_FromFile('D:\\语音数据集\\data_thchs30\\data\\A11_167.WAV')
|
|
|
|
#r = ms.RecognizeSpeech_FromFile('D:\\语音数据集\\data_thchs30\\data\\D4_750.wav')
|
2018-05-28 17:43:50 +08:00
|
|
|
|
2019-01-04 15:38:20 +08:00
|
|
|
K.clear_session()
|
|
|
|
|
2018-04-25 19:50:32 +08:00
|
|
|
print('*[提示] 语音识别结果:\n',r)
|
|
|
|
|
|
|
|
|
|
|
|
ml = ModelLanguage('model_language')
|
|
|
|
ml.LoadModel()
|
|
|
|
|
|
|
|
#str_pinyin = ['zhe4','zhen1','shi4','ji2', 'hao3','de5']
|
|
|
|
#str_pinyin = ['jin1', 'tian1', 'shi4', 'xing1', 'qi1', 'san1']
|
|
|
|
#str_pinyin = ['ni3', 'hao3','a1']
|
|
|
|
str_pinyin = r
|
2018-05-15 21:43:11 +08:00
|
|
|
#str_pinyin = ['su1', 'bei3', 'jun1', 'de5', 'yi4','xie1', 'ai4', 'guo2', 'jiang4', 'shi4', 'ma3', 'zhan4', 'shan1', 'ming2', 'yi1', 'dong4', 'ta1', 'ju4', 'su1', 'bi3', 'ai4', 'dan4', 'tian2','mei2', 'bai3', 'ye3', 'fei1', 'qi3', 'kan4', 'zhan4']
|
2018-04-25 19:50:32 +08:00
|
|
|
r = ml.SpeechToText(str_pinyin)
|
|
|
|
print('语音转文字结果:\n',r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|