基于Python的深度学习的中文语音识别系统

1. Introduction

该系统实现了基于深度框架的语音识别中的声学模型和语言模型建模,其中声学模型包括 CNN-CTC、GRU-CTC、CNN-RNN-CTC,语言模型包含 transformerCBHG,数据集包含 stc、primewords、Aishell、thchs30 四个数据集。

 the  0 th example.

文本结果: lv4 shi4 yang2 chun1 yan1 jing3 da4 kuai4 wen2 zhang1 de di3 se4 si4 yue4 de lin2 luan2 geng4 shi4 lv4 de2 xian1 huo2 xiu4 mei4 shi1 yi4 ang4 ran2
原文结果: lv4 shi4 yang2 chun1 yan1 jing3 da4 kuai4 wen2 zhang1 de di3 se4 si4 yue4 de lin2 luan2 geng4 shi4 lv4 de2 xian1 huo2 xiu4 mei4 shi1 yi4 ang4 ran2
原文汉字: 绿是阳春烟景大块文章的底色四月的林峦更是绿得鲜活秀媚诗意盎然
识别结果: 绿是阳春烟景大块文章的底色四月的林峦更是绿得鲜活秀媚诗意盎然

如果您构建自己的模型,则需要删除现有模型,重新配置参数Trading,具体实现过程参考本页末尾。

[En]

If you build your own model, you need to delete the existing model, reconfigure the parameter training, the specific implementation process refer to the end of this page.

2. 声学模型

声学模型采用 CTC 进行建模,采用 CNN-CTC、GRU-CTC、FSMN 等模型 model_speech,采用 keras 作为编写框架。

3. 语言模型

新增基于 self-attention 结构的语言模型 model_language\transformer.py,该模型已经被证明有强于其他框架的语言表达能力。

基于 CBHG 结构的语言模型 model_language\cbhg.py,该模型之前用于谷歌声音合成,移植到该项目中作为基于神经网络的语言模型。

4. 数据集

Nametraindevtestaishell120098143267176primewords4078350465073thchs-30100008932495st-cmd100006002000

数据标签整理在 data 路径下,其中 primewords、st-cmd 目前未区分训练集测试集。

若需要使用所有数据集,只需解压到统一路径下,然后设置 utils.py 中 datapath 的路径即可。

与数据相关参数在 utils.py 中:

  • data_type: train, test, dev
  • data_path: 对应解压数据的路径
  • thchs30, aishell, prime, stcmd: 是否使用该数据集
  • batch_size: batch_size
  • data_length: 我自己做实验时写小一些看效果用的,正常使用设为 None 即可
  • shuffle:正常训练设为 True,是否打乱训练顺序
def data_hparams():
    params = tf.contrib.training.HParams(

        data_type = 'train',
        data_path = 'data/',
        thchs30 = True,
        aishell = True,
        prime = False,
        stcmd = False,
        batch_size = 1,
        data_length = None,
        shuffle = False)
      return params

5. 配置

使用 train.py 文件进行模型的训练。

声学模型可选 cnn-ctc、gru-ctc,只需修改导入路径即可:

from model_speech.cnn_ctc import Am, am_hparams

from model_speech.gru_ctc import Am, am_hparams

语言模型可选 transformer 和 cbhg:

from model_language.transformer import Lm, lm_hparams

from model_language.cbhg import Lm, lm_hparams

使用 test.py 检查模型识别效果。
模型选择需和训练一致。

the_inputs (InputLayer) (None, None, 200, 1) 0

conv2d_11 (Conv2D) (None, None, 200, 32) 320

batch_normalization_11 (Batc (None, None, 200, 32) 128

conv2d_12 (Conv2D) (None, None, 200, 32) 9248

batch_normalization_12 (Batc (None, None, 200, 32) 128

max_pooling2d_4 (MaxPooling2 (None, None, 100, 32) 0

conv2d_13 (Conv2D) (None, None, 100, 64) 18496

batch_normalization_13 (Batc (None, None, 100, 64) 256

conv2d_14 (Conv2D) (None, None, 100, 64) 36928

batch_normalization_14 (Batc (None, None, 100, 64) 256

max_pooling2d_5 (MaxPooling2 (None, None, 50, 64) 0

conv2d_15 (Conv2D) (None, None, 50, 128) 73856

batch_normalization_15 (Batc (None, None, 50, 128) 512

conv2d_16 (Conv2D) (None, None, 50, 128) 147584

batch_normalization_16 (Batc (None, None, 50, 128) 512

max_pooling2d_6 (MaxPooling2 (None, None, 25, 128) 0

conv2d_17 (Conv2D) (None, None, 25, 128) 147584

batch_normalization_17 (Batc (None, None, 25, 128) 512

conv2d_18 (Conv2D) (None, None, 25, 128) 147584

batch_normalization_18 (Batc (None, None, 25, 128) 512

conv2d_19 (Conv2D) (None, None, 25, 128) 147584

batch_normalization_19 (Batc (None, None, 25, 128) 512

conv2d_20 (Conv2D) (None, None, 25, 128) 147584

batch_normalization_20 (Batc (None, None, 25, 128) 512

reshape_2 (Reshape) (None, None, 3200) 0

dense_3 (Dense) (None, None, 256) 819456

Total params: 1,759,174
Trainable params: 1,757,254
Non-trainable params: 1,920

loading acoustic model…

loading language model…

INFO:tensorflow:Restoring parameters from logs_lm/model


## 使用语音识别系统

`python

for i in range(5):
    print('\n the ', i, 'th example.')
    # 载入训练好的模型,并进行识别
    inputs, outputs = next(am_batch)
    x = inputs['the_inputs']
    y = inputs['the_labels'][0]
    result = am.model.predict(x, steps=1)
    # 将数字结果转化为文本结果
    _, text = decode_ctc(result, train_data.am_vocab)
    text = ' '.join(text)
    print('文本结果:', text)
    print('原文结果:', ' '.join([train_data.am_vocab[int(i)] for i in y]))
    with sess.as_default():
        _, y = next(lm_batch)
        text = text.strip('\n').split(' ')
        x = np.array([train_data.pny_vocab.index(pny) for pny in text])
        x = x.reshape(1, -1)
        preds = sess.run(lm.preds, {lm.x: x})
        got = ''.join(train_data.han_vocab[idx] for idx in preds[0])
        print('原文汉字:', ''.join(train_data.han_vocab[idx] for idx in y[0]))
        print('识别结果:', got)
sess.close()
 the  0 th example.

文本结果: lv4 shi4 yang2 chun1 yan1 jing3 da4 kuai4 wen2 zhang1 de di3 se4 si4 yue4 de lin2 luan2 geng4 shi4 lv4 de2 xian1 huo2 xiu4 mei4 shi1 yi4 ang4 ran2
原文结果: lv4 shi4 yang2 chun1 yan1 jing3 da4 kuai4 wen2 zhang1 de di3 se4 si4 yue4 de lin2 luan2 geng4 shi4 lv4 de2 xian1 huo2 xiu4 mei4 shi1 yi4 ang4 ran2
原文汉字: 绿是阳春烟景大块文章的底色四月的林峦更是绿得鲜活秀媚诗意盎然
识别结果: 绿是阳春烟景大块文章的底色四月的林峦更是绿得鲜活秀媚诗意盎然

 the  1 th example.

文本结果: ta1 jin3 ping2 yao1 bu4 de li4 liang4 zai4 yong3 dao4 shang4 xia4 fan1 teng2 yong3 dong4 she2 xing2 zhuang4 ru2 hai3 tun2 yi4 zhi2 yi3 yi1 tou2 de you1 shi4 ling3 xian1
原文结果: ta1 jin3 ping2 yao1 bu4 de li4 liang4 zai4 yong3 dao4 shang4 xia4 fan1 teng2 yong3 dong4 she2 xing2 zhuang4 ru2 hai3 tun2 yi4 zhi2 yi3 yi1 tou2 de you1 shi4 ling3 xian1
原文汉字: 他仅凭腰部的力量在泳道上下翻腾蛹动蛇行状如海豚一直以一头的优势领先
识别结果: 他仅凭腰部的力量在泳道上下翻腾蛹动蛇行状如海豚一直以一头的优势领先

 the  2 th example.

文本结果: pao4 yan3 da3 hao3 le zha4 yao4 zen3 me zhuang1 yue4 zheng4 cai2 yao3 le yao3 ya2 shu1 di4 tuo1 qu4 yi1 fu2 guang1 bang3 zi chong1 jin4 le shui3 cuan4 dong4
原文结果: pao4 yan3 da3 hao3 le zha4 yao4 zen3 me zhuang1 yue4 zheng4 cai2 yao3 le yao3 ya2 shu1 di4 tuo1 qu4 yi1 fu2 guang1 bang3 zi chong1 jin4 le shui3 cuan4 dong4
原文汉字: 炮眼打好了炸药怎么装岳正才咬了咬牙倏地脱去衣服光膀子冲进了水窜洞
识别结果: 炮眼打好了炸药怎么装岳正才咬了咬牙倏地脱去衣服光膀子冲进了水窜洞

 the  3 th example.

文本结果: ke3 shei2 zhi1 wen2 wan2 hou4 ta1 yi1 zhao4 jing4 zi zhi1 jian4 zuo3 xia4 yan3 jian3 de xian4 you4 cu1 you4 hei1 yu3 you4 ce4 ming2 xian3 bu2 dui4 cheng1
原文结果: ke3 shei2 zhi1 wen2 wan2 hou4 ta1 yi1 zhao4 jing4 zi zhi1 jian4 zuo3 xia4 yan3 jian3 de xian4 you4 cu1 you4 hei1 yu3 you4 ce4 ming2 xian3 bu2 dui4 cheng1
原文汉字: 可谁知纹完后她一照镜子只见左下眼睑的线又粗又黑与右侧明显不对称
识别结果: 可谁知纹完后她一照镜子知见左下眼睑的线右粗右黑与右侧明显不对称

 the  4 th example.

文本结果: yi1 jin4 men2 wo3 bei4 jing1 dai1 le zhe4 hu4 ming2 jiao4 pang2 ji2 de lao3 nong2 shi4 kang4 mei3 yuan2 chao2 fu4 shang1 hui2 xiang1 de lao3 bing1 qi1 zi3 chang2 nian2 you3 bing4 jia1 tu2 si4 bi4 yi1 pin2 ru2 xi3
原文结果: yi1 jin4 men2 wo3 bei4 jing1 dai1 le zhe4 hu4 ming2 jiao4 pang2 ji2 de lao3 nong2 shi4 kang4 mei3 yuan2 chao2 fu4 shang1 hui2 xiang1 de lao3 bing1 qi1 zi3 chang2 nian2 you3 bing4 jia1 tu2 si4 bi4 yi1 pin2 ru2 xi3
原文汉字: 一进门我被惊呆了这户名叫庞吉的老农是抗美援朝负伤回乡的老兵妻子长年有病家徒四壁一贫如洗
识别结果: 一进门我被惊呆了这户名叫庞吉的老农是抗美援朝负伤回乡的老兵妻子长年有病家徒四壁一贫如洗

Original: https://blog.csdn.net/newlw/article/details/122512802
Author: biyezuopinvip
Title: 基于Python的深度学习的中文语音识别系统

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/512910/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球