需自行下载数据集并解压到 /data/speech_data 等目录,还要运行 download_default_datalist.py 下载拼音标签文件;预训练模型不在仓库代码里,需从发布版服务端压缩包获取;TensorFlow 需 2.5-2.11、Python 3.9-3.11,且 GPU 训练需配好 CUDA 11.2 和 cudnn 8.1。

ASRT_SpeechRecognition
nl8590687GPL-3.0更新放缓基于深度学习的中文语音识别系统,用 CNN+CTC 把中文语音转成文字,适合搭建本地语音转写服务。
A Deep-Learning-Based Chinese Speech Recognition System 基于深度学习的中文语音识别系统
git clone https://github.com/nl8590687/ASRT_SpeechRecognition.git
pip install -r requirements.txt训练最低要求 4 核 x86_64 CPU、16GB 内存、NVIDIA 显卡 11GB 以上显存(1080ti 起步)、500GB 硬盘;仅推理可只用 CPU,Windows 10/11 仅支持推理。
基于深度学习的中文语音识别系统,可训练模型并部署 HTTP/gRPC 识别服务
基于深度学习的中文语音识别系统,用 CNN+CTC 把中文语音转成文字,适合搭建本地语音转写服务。
核心能力
- 用 DCNN+CTC 声学模型输出汉语拼音序列
- 用最大熵隐马尔可夫语言模型把拼音转成汉字
- 提供 HTTP 与 gRPC 两种 API 服务端及客户端示例
- 支持多套开源中文语音数据集配置与训练
- 提供 Docker 镜像直接部署服务端
容易踩的坑
- v1.3.0ASRT v1.3.0 Released 最新正式版2022-05-20 · 2022-05-20 11:23 UTC
This is a released version of available. version: 1.3.0 一个可以使用的版本,版本号:1.3.0
-
增加了对grpc协议的支持
-
代码实现上支持了真正的流式识别
-
Added support for grpc protocol
-
The code implementation supports real stream recognition
ASRT v1.x is a brand new version, a better ASRT speech recognition service framework. ASRT v1.x版本是一个全新的版本,一个更好的ASRT语音识别服务框架。
If you want to build an API server that can perform speech recognition and support the recognition process that runs several times continuously, all the files in this directory are suitable for you to run and use directly. 如果您是想搭建一个能够进行语音识别的API服务端,支持持续运行若干次的识别过程,本目录下的所有文件适合您直接运行和使用。
If you want to train your own speech recognition model, the code under GitHub's master branch might be better for you, it gives more options, and dependency files. 如果您想训练自己的语音识别模型,那么GitHub的master分支下的代码可能更适合您,它提供给了更多的选项,以及依赖文件。
This release uses SpeechModel 251BN, which contains trained model parameter files. 本次发布使用的是SpeechModel251BN,内含训练好的模型参数文件。
-
- v1.2.0ASRT v1.2.0 Released2022-03-28 · 2022-03-28 09:14 UTC
查看更新说明
This is a released version of available. version: 1.2.0 一个可以使用的版本,版本号:1.2.0 The version released this time uses the new speech acoustic model SpeechModel251BN, which is faster to train and has a higher recognition rate than the previous SpeechModel251 model! This ASRT release version uses more than 1300 hours of open source data sets for training, and the model recognition effect is more robust and generalization is stronger! The recognition of model parameter files in this version is better than in the previous version, and the correct rate of speech recognition is about 85%. A more performant http-based API was added. 本次发布的版本使用了新的语音声学模型SpeechModel251BN,相比于之前的SpeechModel251模型训练速度更快、识别率更高!本ASRT发布版本使用了1300余小时的开源数据集进行了训练,模型识别效果更鲁棒,泛化性更强!本版本中模型参数文件的识别效果比上一个版本的更佳,语音识别正确率大约85%。一个性能更好的基于http的API接口被加入其中。
ASRT v1.x is a brand new version, a better ASRT speech recognition service framework. ASRT v1.x版本是一个全新的版本,一个更好的ASRT语音识别服务框架。
If you want to build an API server that can perform speech recognition and support the recognition process that runs several times continuously, all the files in this directory are suitable for you to run and use directly. To run the speech recognition API server, please use the asrserver.py file. To run the speech recognition demo client based on HTTP protocol, please use the client.py file after using the asrserver.py file. If you need to modify the recognized recording file path, please enter client.py Modified in. 如果您是想搭建一个能够进行语音识别的API服务端,支持持续运行若干次的识别过程,本目录下的所有文件适合您直接运行和使用。运行语音识别API服务器请使用asrserver_http.py文件,运行基于HTTP协议的语音识别demo客户端请在使用asrserver_http.py文件后使用client_http.py文件,如果需要修改识别的录音文件路径,请在client_http.py中修改。
If you want to train your own speech recognition model, the code under GitHub's master branch might be better for you, it gives more options, and dependency files. 如果您想训练自己的语音识别模型,那么GitHub的master分支下的代码可能更适合您,它提供给了更多的选项,以及依赖文件。
This release uses SpeechModel 251BN, which contains trained model parameter files. 本次发布使用的是SpeechModel251BN,内含训练好的模型参数文件。
- v1.1.2ASRT v1.1.2 Released2022-03-22 · 2022-03-22 13:15 UTC
查看更新说明
This is a released version of available. version: 1.1.2 一个可以使用的版本,版本号:1.1.2 The version released this time uses more open source data sets for training, the model recognition effect is more robust, and the generalization is stronger! There are better performance model parameter files being included than the last. A better performance http-based API interface was added. 本次发布的版本使用了更多的开源数据集进行了训练,模型识别效果更鲁棒,泛化性更强!本版本中模型参数文件的效果比上一个版本的更佳。一个性能更好的基于http的API接口被加入其中。
ASRT v1.x is a brand new version, a better ASRT speech recognition service framework. ASRT v1.x版本是一个全新的版本,一个更好的ASRT语音识别服务框架。
If you want to build an API server that can perform speech recognition and support the recognition process that runs several times continuously, all the files in this directory are suitable for you to run and use directly. To run the speech recognition API server, please use the asrserver.py file. To run the speech recognition demo client based on HTTP protocol, please use the client.py file after using the asrserver.py file. If you need to modify the recognized recording file path, please enter client.py Modified in. 如果您是想搭建一个能够进行语音识别的API服务端,支持持续运行若干次的识别过程,本目录下的所有文件适合您直接运行和使用。运行语音识别API服务器请使用asrserver_http.py文件,运行基于HTTP协议的语音识别demo客户端请在使用asrserver_http.py文件后使用client_http.py文件,如果需要修改识别的录音文件路径,请在client_http.py中修改。
If you want to train your own speech recognition model, the code under GitHub's master branch might be better for you, it gives more options, and dependency files. 如果您想训练自己的语音识别模型,那么GitHub的master分支下的代码可能更适合您,它提供给了更多的选项,以及依赖文件。
This release still uses SpeechModel 251, which contains trained model parameter files. 本次发布仍然使用的是SpeechModel251,内含训练好的模型参数文件。
- v1.1.1ASRT v1.1.1 Released2022-03-05 · 2022-03-05 11:48 UTC
查看更新说明
This is a released version of available. version: 1.1.1 一个可以使用的版本,版本号:1.1.1 The version released this time uses more open source data sets for training, the model recognition effect is more robust, and the generalization is stronger! There are better performance model parameter files being included than the last. A better performance http-based API interface was added. 本次发布的版本使用了更多的开源数据集进行了训练,模型识别效果更鲁棒,泛化性更强!本版本中模型参数文件的效果比上一个版本的更佳。一个性能更好的基于http的API接口被加入其中。
ASRT v1.x is a brand new version, a better ASRT speech recognition service framework. ASRT v1.x版本是一个全新的版本,一个更好的ASRT语音识别服务框架。
If you want to build an API server that can perform speech recognition and support the recognition process that runs several times continuously, all the files in this directory are suitable for you to run and use directly. To run the speech recognition API server, please use the asrserver.py file. To run the speech recognition demo client based on HTTP protocol, please use the client.py file after using the asrserver.py file. If you need to modify the recognized recording file path, please enter client.py Modified in. 如果您是想搭建一个能够进行语音识别的API服务端,支持持续运行若干次的识别过程,本目录下的所有文件适合您直接运行和使用。运行语音识别API服务器请使用asrserver.py文件,运行基于HTTP协议的语音识别demo客户端请在使用asrserver.py文件后使用client.py文件,如果需要修改识别的录音文件路径,请在client.py中修改。
If you want to train your own speech recognition model, the code under GitHub's master branch might be better for you, it gives more options, and dependency files. 如果您想训练自己的语音识别模型,那么GitHub的master分支下的代码可能更适合您,它提供给了更多的选项,以及依赖文件。
This release still uses SpeechModel 251, which contains trained model parameter files. 本次发布仍然使用的是SpeechModel251,内含训练好的模型参数文件。
- v1.1.0-update1ASRT v1.1.0-update1 Released2021-12-29 · 2021-12-29 05:15 UTC
这个版本没有写更新说明。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。

ASRT是一个基于深度学习的中文语音识别系统,如果您觉得喜欢,请点一个 "Star" 吧~
ReadMe Language | 中文版 | English |
ASRT项目主页 | 发布版下载 | 查看本项目的Wiki文档 | 实用效果体验Demo | 打赏作者
如果程序运行期间或使用中有什么问题,可以及时在issue中提出来,我将尽快做出答复。本项目作者交流QQ群:894112051 ,加微信群请先加AI柠檬微信号:ailemon-me ,并备注“ASRT语音识别”
提问前请仔细查看项目文档、 FAQ常见问题 以及Issues 避免重复提问
如果程序运行时有任何异常情况,在提问时请发出完整截图,并注明所使用的CPU架构,GPU型号,操作系统、Python,TensorFlow和CUDA版本,以及是否修改过任何代码或增删数据集等。
Introduction 简介
本项目使用tensorFlow.keras基于深度卷积神经网络和长短时记忆神经网络、注意力机制以及CTC实现。
训练模型的最低软硬件要求
硬件
- CPU: 4核 (x86_64, amd64) +
- RAM: 16 GB +
- GPU: NVIDIA, Graph Memory 11GB+ (1080ti起步)
- 硬盘: 500 GB 机械硬盘(或固态硬盘)
软件
- Linux: Ubuntu 20.04+ / CentOS 7+ (训练+推理) 或 Windows: 10/11(仅推理)
- Python: 3.9 - 3.11 及后续版本
- TensorFlow: 2.5 - 2.11 及后续版本
快速开始
以在Linux系统下的操作为例:
首先通过Git将本项目克隆到您的计算机上,然后下载本项目训练所需要的数据集,下载链接详见文档末尾部分。
$ git clone https://github.com/nl8590687/ASRT_SpeechRecognition.git
或者您也可以通过 "Fork" 按钮,将本项目Copy一份副本,然后通过您自己的SSH密钥克隆到本地。
通过git克隆仓库以后,进入项目根目录;并创建一个存储数据的子目录, 例如 /data/speech_data (可使用软链接代替),然后将下载好的数据集直接解压进去
注意,当前版本中,在配置文件里,默认添加了Thchs30、ST-CMDS、Primewords、aishell-1、aidatatang200、MagicData 六个数据集,如果不需要请自行删除。如果要使用其他数据集需要自行添加数据配置,并提前使用ASRT支持的标准格式整理数据。
$ cd ASRT_SpeechRecognition
$ mkdir /data/speech_data
$ tar zxf <数据集压缩文件名> -C /data/speech_data/
下载默认数据集的拼音标签文件:
$ python download_default_datalist.py
目前可用的模型有24、25、251和251bn
运行本项目之前,请安装必要的Python3版依赖库
本项目开始训练请执行:
$ python3 train_speech_model.py
本项目开始测试请执行:
$ python3 evaluate_speech_model.py
测试之前,请确保代码中填写的模型文件路径存在。
预测单条音频文件的语音识别文本:
$ python3 predict_speech_file.py
启动ASRT HTTP协议的API服务器启动请执行:
$ python3 asrserver_http.py
本地测试调用HTTP协议API服务是否成功:
$ python3 client_http.py
启动ASRT GRPC协议的API服务器启动请执行:
$ python3 asrserver_grpc.py
本地测试调用GRPC协议API服务是否成功:
$ python3 client_grpc.py
请注意,开启API服务器之后,需要使用本ASRT项目对应的客户端软件来进行语音识别,详见Wiki文档下载ASRT语音识别客户端SDK和Demo。
如果要训练和使用非251bn版模型,请在代码中 from speech_model.xxx import xxx 的相应位置做修改。
使用docker直接部署ASRT:
$ docker pull ailemondocker/asrt_service:1.3.0
$ docker run --rm -it -p 20001:20001 -p 20002:20002 --name asrt-server -d ailemondocker/asrt_service:1.3.0
仅CPU运行推理识别,不作训练
Model 模型
Speech Model 语音模型
DCNN + CTC
其中,输入的音频的最大时间长度为16秒,输出为对应的汉语拼音序列
- 关于下载已经训练好的模型的问题
已经训练好的模型包含在发布版服务端程序压缩包里面,发布版成品服务端程序可以在此下载:ASRT下载页面。
Github本仓库下Releases页面里面还包括各个不同版本的介绍信息,每个版本下方的zip压缩包也是包含已经训练好的模型的发布版服务端程序压缩包。
Language Model 语言模型
基于概率图的最大熵隐马尔可夫模型
输入为汉语拼音序列,输出为对应的汉字文本
About Accuracy 关于准确率
当前,最好的模型在测试集上基本能达到85%的汉语拼音正确率
Python依赖库
- tensorFlow (2.5-2.11+)
- numpy
- wave
- matplotlib
- scipy
- requests
- flask
- waitress
- grpcio / grpcio-tools / protobuf
不会安装环境的同学请直接运行以下命令(前提是有GPU且已经安装好 Python3.9、CUDA 11.2 和 cudnn 8.1):
$ pip install -r requirements.txt
Data Sets 数据集
完整内容请查看:几个最新免费开源的中文语音数据集
| 数据集 | 时长 | 大小 | 国内下载 | 国外下载 |
|---|---|---|---|---|
| THCHS30 | 40h | 6.01G | data_thchs30.tgz | data_thchs30.tgz |
| ST-CMDS | 100h | 7.67G | ST-CMDS-20170001_1-OS.tar.gz | ST-CMDS-20170001_1-OS.tar.gz |
| AIShell-1 | 178h | 14.51G | data_aishell.tgz | data_aishell.tgz |
| Primewords | 100h | 8.44G | primewords_md_2018_set1.tar.gz | primewords_md_2018_set1.tar.gz |
| MagicData | 755h | 52G/1.0G/2.2G | train_set.tar.gz / dev_set.tar.gz / test_set.tar.gz | train_set.tar.gz / dev_set.tar.gz / test_set.tar.gz |
注:AISHELL-1 数据集解压方法
$ tar xzf data_aishell.tgz
$ cd data_aishell/wav
$ for tar in *.tar.gz; do tar xvf $tar; done
特别鸣谢!感谢前辈们的公开语音数据集
如果提供的数据集链接无法打开和下载,请点击该链接 OpenSLR
ASRT语音识别API客户端调用SDK
ASRT为客户端通过RPC方式调用开发语音识别功能提供了不同平台和编程语言的SDK接入能力,对于其他平台,可直接通过调用通用RESTful Open API方式进行语音识别功能接入。具体接入步骤请看ASRT项目文档。
| 客户端平台 | 项目仓库链接 |
|---|---|
| Windows客户端SDK和Demo | ASRT_SDK_WinClient |
| 跨平台Python3客户端SDK和Demo | ASRT_SDK_Python3 |
| 跨平台Golang客户端SDK和Demo | asrt-sdk-go |
| Java客户端SDK和Demo | ASRT_SDK_Java |
ASRT相关资料
ASRT的原理请查看本文:
ASRT训练和部署教程请看:
关于经常被问到的统计语言模型原理的问题,请看:
关于CTC的问题请看:
更多内容请访问作者的博客:AI柠檬博客
或使用AI柠檬站内搜索引擎进行相关信息的搜索
License 开源许可协议
参考引用本项目
Contributors 贡献者们
@nl8590687 (repo owner)