Skip to main content

Automatic speech recognition toolkit on Pytorch

Project description

python version GitHub forks GitHub Repo stars GitHub 支持系统

MASR流式与非流式语音识别项目

MASR是一款基于Pytorch实现的自动语音识别框架,MASR全称是神奇的自动语音识别框架(Magical Automatic Speech Recognition),当前为V2版本,如果想使用V1版本,请在这个分支r1.x。MASR致力于简单,实用的语音识别项目。可部署在服务器,Nvidia Jetson设备,未来还计划支持Android等移动设备。

如果熟悉PaddlePaddle,请优先使用:PPASR

欢迎大家扫码入QQ群讨论,或者直接搜索QQ群号1169600237,问题答案为博主Github的IDyeyupiaoling

本项目使用的环境:

  • Anaconda 3
  • Python 3.8
  • Pytorch 1.12.1
  • Windows 10 or Ubuntu 18.04

项目快速了解

  1. 本项目支持流式识别模型deepspeech2conformersqueezeformer,每个模型又分online(在线)和offline(离线),对应的是流式识别和非流式识别。
  2. 本项目支持两种解码器,分别是集束搜索解码器ctc_beam_search和贪心解码器ctc_greedy,集束搜索解码器ctc_beam_search准确率更高,但不支持Windows。
  3. 下面提供了一系列预训练模型的下载,下载预训练模型之后,需要把全部文件复制到项目根目录,并执行导出模型才可以使用语音识别。

更新记录

  • 2022.11: 正式发布最终级的V2版本。

视频讲解

这个是PPSAR的视频教程,项目是通用的,可以参考使用。

模型下载

  1. conformer预训练模型列表:
使用模型 数据集 预处理方式 语言 测试集字错率(词错率) 下载地址
conformer_online WenetSpeech (10000小时) fbank 中文
conformer_online aishell (179小时) fbank 中文 0.04491 点击下载
conformer_offline aishell (179小时) fbank 中文 0.04342 点击下载
conformer_online Librispeech (960小时) fbank 英文 点击下载
conformer_offline Librispeech (960小时) fbank 英文 点击下载
  1. squeezeformer预训练模型列表:
使用模型 数据集 预处理方式 语言 测试集字错率(词错率) 下载地址
squeezeformer_online aishell (179小时) fbank 中文 0.04137 点击下载
squeezeformer_offline aishell (179小时) fbank 中文 0.04074 点击下载
squeezeformer_online Librispeech (960小时) fbank 英文 点击下载
squeezeformer_offline Librispeech (960小时) fbank 英文 点击下载
  1. deepspeech2预训练模型列表:
使用模型 数据集 预处理方式 语言 测试集字错率(词错率) 下载地址
deepspeech2_online aishell (179小时) fbank 中文 0.06907 点击下载
deepspeech2_offline aishell (179小时) fbank 中文 0.07600 点击下载
deepspeech2_online Librispeech (960小时) fbank 英文 点击下载
deepspeech2_offline Librispeech (960小时) fbank 英文 点击下载

说明:

  1. 这里字错率或者词错率是使用eval.py程序并使用集束搜索解码ctc_beam_search方法计算得到的。
  2. 没有提供预测模型,需要把全部文件复制到项目的根目录下,执行export_model.py导出预测模型。

有问题欢迎提 issue 交流

语言模型

语言模型 训练数据 数据量 文件大小 说明
自定义中文语言模型 自定义中文语料 约2千万 572 MB 训练参数-o 5,无剪枝
英文语言模型 CommonCrawl 18.5亿 8.3 GB 训练参数-o 5,剪枝参数'--prune 0 1 1 1 1
中文语言模型(剪枝) 百度内部语料库 1.3亿 2.8 GB 训练参数-o 5,剪枝参数'--prune 0 1 1 1 1
中文语言模型 百度内部语料库 37亿 70.4 GB 训练参数-o 5,无剪枝

快速使用

  1. 短语音识别
from masr.predict import MASRPredictor

predictor = MASRPredictor(model_tag='conformer_online_fbank_aishell')

wav_path = 'dataset/test.wav'
result = predictor.predict(audio_data=wav_path, use_pun=False)
score, text = result['score'], result['text']
print(f"识别结果: {text}, 得分: {int(score)}")
  1. 长语音识别
from masr.predict import MASRPredictor

predictor = MASRPredictor(model_tag='conformer_online_fbank_aishell')

wav_path = 'dataset/test_long.wav'
result = predictor.predict_long(audio_data=wav_path, use_pun=False)
score, text = result['score'], result['text']
print(f"识别结果: {text}, 得分: {score}")
  1. 模拟流式识别
import time
import wave

from masr.predict import MASRPredictor

predictor = MASRPredictor(model_tag='conformer_online_fbank_aishell')

# 识别间隔时间
interval_time = 0.5
CHUNK = int(16000 * interval_time)
# 读取数据
wav_path = 'dataset/test.wav'
wf = wave.open(wav_path, 'rb')
data = wf.readframes(CHUNK)
# 播放
while data != b'':
    start = time.time()
    d = wf.readframes(CHUNK)
    result = predictor.predict_stream(audio_data=data, use_pun=False, is_end=d == b'')
    data = d
    if result is None: continue
    score, text = result['score'], result['text']
    print(f"【实时结果】:消耗时间:{int((time.time() - start) * 1000)}ms, 识别结果: {text}, 得分: {int(score)}")
# 重置流式识别
predictor.reset_stream()

文档教程

相关项目

参考资料

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

masr-2.1.0-py3-none-any.whl (1.6 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page