基于Python的语音识别系统的设计与实现
摘 要
随着互联网的发展,语音文件成为了人们接触得越来越多文件。如何高效的从一段录音中提取出关键信息,提取出其中人们感兴趣的内容,直观的呈现给人门。本文以DFSMN作为声学模型,引入TensorFlowr模型,将语音识别转化为翻译任务展开深入研究,具有一定的理论意义和研究价值。
本文阐述了语音识别领域的几种主流深度学习模型。根据深度学习理论,设计了基于TensorFlow的连续语音识别系统的总体方案。重点研究语音特征提取方法和语言模型TensorFlow的不足,对特征提取方法和语言模型进行优化。
针对梅尔频率倒谱系数特征(Mel Frequency Cepstrum Coefficient, MFCC)在深度模型里存在语音信息表征能力弱的问题,提出一种对数梅尔滤波组((Log MelFilter-bank, Fbank)特征结合卷积神经网络(Convolutional Neural Networks, CNN)再提取的特征提取方法,并和DFSMN结合构建声学模型CNN-DFSMN,实现语音转拼音任务。实验结果表明,Fbank特征结合CNN再提取的特征提取方法与其他特征提取方法相比,语音信息表征能力更强,模型的字符错误率(Character Error Rate, CER)更低。
针对语言模型TensorFlowr存在计算量复杂、模型泛化能力不足导致识别率不高,识别速度慢的问题,提出一种基于Hadamard矩阵的注意力计算改进方法。该方法利用设置不同阂值生成的Hadamard矩阵与注意力矩阵做点积,从而生成新的注意力矩阵。实验结果表明,利用Hadmard矩阵改进后的TensorFlow模型与初始TensorFlowr模型相比,语言模型的识别时间和CER都有所降低。
关键词:Python,语音识别,语音处理,TensorFlow,模型
The Design and Implementation of the Speech Recognition System Based on Python
Abstract
With the development of the Internet, voice files have become more and more accessible files.How to efficiently extract the key information from a recording, extract the content that people are interested in, and intuitively present it to the door.This paper takes DFSMN as an acoustic model and introduces the TensorFlowr model to transform speech recognition into a translation task, which has certain theoretical significance and research value.
This paper describes several mainstream deep learning models in the field of speech recognition.According to the deep learning theory, the overall scheme of the TensorFlow-based continuous speech learning system is designed.Focus on the shortcomings of speech feature extraction method and language model TensorFlow, and optimize the feature extraction method and language model.
For Mer frequency inversion coefficient characteristics (Mel Frequency Cepstrum Coefficient, MFCC) has the problem of weak speech information representation ability in the deep model, Introduce a log-Mayer filter group ((Log MelFilter-bank, Fbank) features combined with convolutional neural networks (Convolutional Neural Networks, CNN) The feature extraction method for reextraction, Combined with DFSMN to construct the acoustic model CNN-DFSMN, Realize the voice to pinyin task.The experimental results show that the feature extraction method of Fbank feature extraction has stronger representation ability and lower character error rate (Character Error Rate, CER).
An attention computational improvement method based on Hadamard matrix is proposed for the problems that language model TensorFlowr has complex computation and insufficient model generalization ability.This method uses the Hadamard matrix generated with different threshold values to generate a new attention matrix.Experimental results show that the improved TensorFlow model using the Hadmard matrix has both reduced recognition time and CER of the language model compared with the initial TensorFlowr model. Key words: Python, speech recognition, speech processing, TensorFlow, model
Key words: Haojing College of Shaanxi University of Science & Technology,Undergraduates
目 录
1 绪论 1
1.1 研究背景及意义 1
1.2 国内外研究现状 2
1.2.1 语音识别中声学模型研究现状 2
1.2.2 语音识别中语言模型研究现状 3
1.3 主要研究内容 4
2 语音识别系统需求分析 5
2.1 商务需求 5
2.2 教育需求 6
2.3 刑侦需求 6
2.4 国家安全需求 6
3 语音识别系统方案设计 8
3.1 语音信号的预处理 8
3.2 语音识别系统的分类 8
3.2.1 基于概率模型的语音识别系统 8
3.2.2 端到端语音识别系统 9
3.3 语音特征的提取 9
3.4 语音模型的构建 10
4 语音识别系统实现 12
4.1 系统介绍 12
4.2 语音数据集介绍 12
4.2.1 不同人的声音 12
4.2.2 每人不同单词的发音 12
4.2.3 声音波形 13
4.3 代码功能实现 13
4.3.1 项目思路 13
4.3.2 依赖环境及代码目录 13
4.3.3 数据读取与预处理(data_create.py) 14
4.3.4 语音数据分帧及mfcc处理(data_create.py) 15
4.3.5 模型构建(model.py) 16
4.3.6 模型训练(model_train.py) 20
4.3.7 模型评估(model_test.py) 20
4.3.8 模型训练可视化 21
4.3.9 模型预测(func_test.py) 22
结 论 25
致 谢 26
参考文献 27
3 语音识别系统方案设计
语音识别系统可分为以概率模型为基础的语音识别系统和端到端语音识别系统,其中有很多经典主流的语音识别模型。本章主要对语音识别系统中的预处理工作,目前语音识别领域中两种主流的语音识别系统以及几种主流语音识别模型进行研究,并且给出连续语音识别系统性能的评价标准,为后文连续语音识别技术的研究及改进提供理论依据。
3.1 语音信号的预处理
在采集音频时,实验人员的发音、采集设备以及周围的环境都会影响音频信号的质量,从而出现静音、混叠、噪声、失真等现象。因此在对语音信号正式使用前,必须先进行预处理操作。通过降噪、信道增强、端点检测等预处理技术,以及快速傅里叶变换将时域信号转化成频域信号,从而有效地提取特征信息,便于声学模型的识别。下面对预处理过程进行详细研究。
语音的采样和量化,就是将语音信号模拟信号数字化。采样周期按照奈奎斯特采样率计算,这是为了防止语音信号在频域分析时,可能会发生混叠失真的情况。
本文转载自:http://www.biyezuopin.vip/onews.asp?id=16495
import os
import matplotlib.pyplot as plt
from collections import Counter
import numpy as np
from tensorflow import keras
from model import ResNetModel
import tensorflow as tf
def load_data():
# 读取数据
x = np.load('train_data/data.npy')
y = np.load('train_data/label.npy')
num = len(Counter(y))
print("类别数量为:", num)
return x, y, num
if __name__ == '__main__':
data, label, label_num = load_data()
# 修改data的shape
data = data.reshape((data.shape[0], data.shape[1], data.shape[2], 1))
# 模型参数
model_param = {
"label_count": label_num,
"num_b": 20
}
data_shape = (data.shape[1], data.shape[2], data.shape[3])
Resnetmodel = ResNetModel(input_shape=data_shape, classes=model_param['label_count'])
ResNet_model = Resnetmodel.ResNet50()
ResNet_model.summary()
learning_rate = 1e-4
num_epochs = 10
batch_size = 16
# 设置模型log输出地址
log_dir = os.path.join("logs/")
if not os.path.exists(log_dir):
os.mkdir(log_dir)
# 设置模型训练优化器,默认为Adam
optimizer = keras.optimizers.Adam(learning_rate)
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
# 编译模型来配置学习过程
ResNet_model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# 模型训练
history = ResNet_model.fit(data, label, epochs=num_epochs, batch_size=batch_size, callbacks=[tensorboard_callback],
validation_split=0.2)
# 保存模型
model_path = 'models_save/resnet_model.h5'
ResNet_model.save(model_path)
print("完成模型训练,保存地址:", model_path)