本文主要针对中文语音识别问题,选用常用的模型进行 离线 demo 搭建及实践说明。
语音识别技术就是让机器通过识别和理解过程把语音信号转变为相应的文本或命令的技术。
主要有基于动态时间规整(DTW)算法、基于非参数模型的矢量量化(VQ)方法、基于参数模型的隐马尔可夫模型(HMM)的方法、基于人工神经网络(ANN)和支持向量机等语音识别方法。
(1)特定人语音识别(SD):只能辨认特定使用者的语音,训练→使用。
(2)非特定人语音识别(SI):可辨认任何人的语音,无须训练。
(1)孤立词识别:每次只能识别单个词汇。
(2)连续语音识别:用者以正常语速说话,即可识别其中的语句。
语音识别系统的模型通常由声学模型和语言模型两部分组成,分别对应于:
整体流程图如下所示:
说明:https://cmusphinx.github.io/wiki/
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio
需要下载安装两个库,pyaudio,PocketSphinx,
在安装完sphinx后默认只支持英文,在存放模型的路径下只有一个文件名为en-US,所以这里需要添加一个处理中文的模型
conda create --name speech_recognition python==3.7
activate speech_recognition
# conda 安装好像也可以解决依赖的问题,还是下载后安装比较好
conda install pyaudio
pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
conda install ipykernel
# 下面两种安装方式
python -m pip install pocketsphinx-0.1.15-cp37-cp37m-win_amd64.whl
pip install pocketsphinx-0.1.15-cp37-cp37m-win_amd64.whl
# cmd 下 获取历史命令
doskey /history
下载地址: https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/
解压文件,在 虚环境 目录下找到Lib\site-packages\speech_recognition 新建zh-CN 需要注意:
先说结论:效果太差
先用了一段 ,中文普通话,用英文识别测试一下,居然不报错。
# -*- coding: utf-8 -*-
import speech_recognition as sr
r = sr.Recognizer()
harvard = sr.AudioFile(r"test.wav")
with harvard as source:
audio = r.record(source)
try:
print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
接着使用普通话 的配置进行识别,我录音说的是:同学们大家好,今天给大家讲解自然语言处理 和程序员面试宝典。
r = sr.Recognizer()
harvard = sr.AudioFile(r"test2.wav")
with harvard as source:
audio = r.record(source)
try:
print("Sphinx thinks you said " +r.recognize_sphinx(audio, language='zh-CN'))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
识别结果是:
Sphinx thinks you said 同学 们 后 分 中心 用户 的 大家 见面 会 今天 过来 给 大家 讲述 以下 村民 搬出 当时 渐 成 学院 面世 国电 今天 天气 从武 行 综合 治理 等 部门 项目 女友
参照官方文档:https://www.paddlepaddle.org.cn/documentation/docs/zh/install/index_cn.html
确认 Python 和 pip 是 64 bit,并且处理器架构是x86_64(或称作 x64、Intel 64、AMD64)架构,目前PaddlePaddle不支持arm64架构。下面的第一行输出的是 “64bit” ,第二行输出的是 “x86_64” 、 “x64” 或 “AMD64” 即可:
python -c "import platform;print(platform.architecture()[0]);print(platform.machine())"
conda create --name my_paddle
conda activate my_paddle
conda install paddlepaddle --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/
conda install ipykernel
验证安装
使用 python 进入python解释器,输入:
import paddle
print(paddle.__version__)
import paddle
paddle.utils.run_check()
2.1.1 Running verify PaddlePaddle program … PaddlePaddle works well on 1 CPU. W0703 16:47:17.045516 28048 fuse_all_reduce_op_pass.cc:76] Find all_reduce operators: 2. To make the speed faster, some all_reduce ops are fused during training, after fusion, the number of all_reduce ops is 2. PaddlePaddle works well on 2 CPUs. PaddlePaddle is installed successfully! Let’s start deep learning with PaddlePaddle now.
如果出现 PaddlePaddle is installed successfully!,说明您已成功安装。
PaddlePaddle 提供了丰富的计算单元,使得用户可以采用模块化的方法解决各种学习问题。在此Repo中,我们展示了如何用 PaddlePaddle来解决常见的机器学习任务,提供若干种不同的易学易用的神经网络模型。PaddlePaddle用户可领取免费Tesla V100在线算力资源,高效训练模型,每日登陆即送12小时,连续五天运行再加送48小时,前往使用免费算力。
语音识别的内容在下方链接: https://github.com/PaddlePaddle/models#PaddleSpeech
看完这个语音识别的简介,发现要装的东西好像都是linux里面的,所以,咱一开始,最好使用linux系统去装,我只好用windows 下的 WSL 的ubuntu 再装一个paddlepaddle 的子环境了.
PaddleASR is an open-source implementation of end-to-end Automatic Speech Recognition (ASR) engine, with PaddlePaddle platform. Our vision is to empower both industrial application and academic research on speech recognition, via an easy-to-use, efficient, samller and scalable implementation, including training, inference & testing module, and deployment.
PaddleASR是一个采用PaddlePaddle平台的端到端自动语音识别(ASR)引擎的开源项目, 我们的愿景是为语音识别在工业应用和学术研究上,提供易于使用、高效、小型化和可扩展的工具,包括训练,推理,以及 部署。
安装要求:
参考链接:
Sphinx: https://blog.csdn.net/qq_40965177/article/details/86766703
Sphinx 的使用: https://zhuanlan.zhihu.com/p/92612487
paddle https://blog.csdn.net/qq_33200967/article/details/102904306 https://blog.csdn.net/yaningli/article/details/80223036 https://github.com/yeyupiaoling/PaddlePaddle-DeepSpeech