Monotonic-Aligner语音时间戳预测-16k-离线

我要开发同款
匿名用户2024年07月31日
48阅读
所属分类ai、Non-autoregressive、pytorch、Alibaba、Timestamp、FunASR、CER、audio
开源地址https://modelscope.cn/models/iic/speech_timestamp_prediction-v1-16k-offline
授权协议Apache License 2.0

作品详情

Highlights

  • 通过参数量较小的encoder与反卷积predictor实现时间戳预测,时间戳准确率与kaldi force-alignment系统相当(详见下方实验结果)。

FunASR开源项目介绍

FunASR希望在语音识别的学术研究和工业应用之间架起一座桥梁。通过发布工业级语音识别模型的训练和微调,研究人员和开发人员可以更方便地进行语音识别模型的研究和生产,并推动语音识别生态的发展。让语音识别更有趣!

github仓库 | 最新动态 | 环境安装 | 服务部署 | 模型库 | 联系我们

模型原理介绍

Timestamp Prediction Model

目前大部分工业语音识别系统使用外接的强制对齐模型预测ASR模型识别结果的时间戳,这引入了额外的计算开销与时间开销,FunASR提供一种在ASR任务过程中天然的预测识别结果时间戳的方法。 Paraformer通过encoder之后的predictor模块实现token级别的声学表征的生成,predictor中的cif机制通过累积帧级别权重计算了每个token的持续区间与发射位置,这使得通过predictor实现与ASR任务一体化的时间戳预测(Timestamp Prediction, TP)成为了可能。本模型为Paraformer-large-长音频版的衍生模型,通过较小参数量的encoder与升采样cif predictor实现了时间戳预测功能,方便用户自由搭建ASR链路中的功能环节。

其核心点主要有:

  • Upsample Predictor 模块:在低帧率模型中predictor产生的帧级别权重可能存在预测不稳定的问题,表现为首尾帧出字与连续帧出字,这为基于cif权重的时间戳预测带来了困扰。本模型
  • (1) 在predictor的线性层之前引入了反卷积升采样模块与lstm模块,在多倍帧率的情况下预测权重;
  • (2) 通过scaled cif对权重进行尺度缩小与平滑,使得cif权重不表现为一个peak而是一段累积过程。通过上述两个操作得到了能用于时间戳预测的帧权重。
  • 基于约5w小时工业数据训练的时间戳预测模型,鲁棒性更强,时间戳准确率更高。

基于ModelScope进行推理

  • 推理支持音频格式如下:
  • wav文件路径,例如:data/test/audios/asr_example.wav
  • pcm文件路径,例如:data/test/audios/asr_example.pcm
  • wav文件url,例如:https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/testaudio/asrexample_timestamps.wav
  • wav二进制数据,格式bytes,例如:用户直接从文件里读出bytes数据或者是麦克风录出bytes数据。
  • 已解析的audio音频,例如:audio, rate = soundfile.read("asrexamplezh.wav"),类型为numpy.ndarray或者torch.Tensor。
  • wav.scp文件,需符合如下要求:
cat wav.scp
asr_example1  data/test/audios/asr_example1.wav
asr_example2  data/test/audios/asr_example2.wav
...
  • 若输入格式wav文件url,api调用方式可参考如下范例:
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

inference_pipline = pipeline(
    task=Tasks.speech_timestamp,
    model='iic/speech_timestamp_prediction-v1-16k-offline',
    model_revision="v2.0.4",
    output_dir='./tmp')

wav_file = "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_timestamps.wav"
text_file = "一 个 东 太 平 洋 国 家 为 什 么 跑 到 西 太 平 洋 来 了 呢"
rec_result = inference_pipline(input=(wav_file, text_file), data_type=("sound", "text"))
print(rec_result)
  • 若输入格式为文件wav.scp与对应的抄本text.txt(注:文件名需要以.txt结尾),可添加 output_dir 参数将识别结果写入文件中,api调用方式可参考如下范例:
wav_file = "./wav.scp"
text_file = "/text.txt"
rec_result = inference_pipline(input=(wav_file, text_file), data_type=("sound", "text"))
print(rec_result)

输出的结果为带有静音标注时间戳的字符串以及排除了静音标注的与token数量一致的时间戳列表:

'text': ' 0.000 0.380;一 0.380 0.560;个 0.560 0.800;东 0.800 0.980;太 0.980 1.140;平 1.140 1.260;洋 1.260 1.440;国 1.440 1.680;家 1.680 1.920; 1.920 2.040;为 2.040 2.200;什 2.200 2.320;么 2.320 2.500;跑 2.500 2.680;到 2.680 2.880;西 2.880 3.060;太 3.060 3.200;平 3.200 3.380;洋 3.380 3.500;来 3.500 3.660;了 3.660 3.800;呢 3.800 4.160; 4.160 4.440;',

'timestamp': [[380, 560], [560, 800], [800, 980], [980, 1140], [1140, 1260], [1260, 1440], [1440, 1680], [1680, 1920], [2040, 2200], [2200, 2320], [2320, 2500], [2500, 2680], [2680, 2880], [2880, 3060], [3060, 3200], [3200, 3380], [3380, 3500], [3500, 3660], [3660, 3800], [3800, 4160]]

基于FunASR进行推理

下面为快速上手教程,测试音频(中文英文

可执行命令行

在命令行终端执行:

funasr +model=paraformer-zh +vad_model="fsmn-vad" +punc_model="ct-punc" +input=vad_example.wav

注:支持单条音频文件识别,也支持文件列表,列表为kaldi风格wav.scp:wav_id wav_path

python示例

非实时语音识别

from funasr import AutoModel
# paraformer-zh is a multi-functional asr model
# use vad, punc, spk or not as you need
model = AutoModel(model="paraformer-zh", model_revision="v2.0.4",
                  vad_model="fsmn-vad", vad_model_revision="v2.0.4",
                  punc_model="ct-punc-c", punc_model_revision="v2.0.4",
                  # spk_model="cam++", spk_model_revision="v2.0.2",
                  )
res = model.generate(input=f"{model.model_path}/example/asr_example.wav", 
            batch_size_s=300, 
            hotword='魔搭')
print(res)

注:model_hub:表示模型仓库,ms为选择modelscope下载,hf为选择huggingface下载。

实时语音识别

from funasr import AutoModel

chunk_size = [0, 10, 5] #[0, 10, 5] 600ms, [0, 8, 4] 480ms
encoder_chunk_look_back = 4 #number of chunks to lookback for encoder self-attention
decoder_chunk_look_back = 1 #number of encoder chunks to lookback for decoder cross-attention

model = AutoModel(model="paraformer-zh-streaming", model_revision="v2.0.4")

import soundfile
import os

wav_file = os.path.join(model.model_path, "example/asr_example.wav")
speech, sample_rate = soundfile.read(wav_file)
chunk_stride = chunk_size[1] * 960 # 600ms

cache = {}
total_chunk_num = int(len((speech)-1)/chunk_stride+1)
for i in range(total_chunk_num):
    speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride]
    is_final = i == total_chunk_num - 1
    res = model.generate(input=speech_chunk, cache=cache, is_final=is_final, chunk_size=chunk_size, encoder_chunk_look_back=encoder_chunk_look_back, decoder_chunk_look_back=decoder_chunk_look_back)
    print(res)

注:chunk_size为流式延时配置,[0,10,5]表示上屏实时出字粒度为10*60=600ms,未来信息为5*60=300ms。每次推理输入为600ms(采样点数为16000*0.6=960),输出为对应文字,最后一个语音片段输入需要设置is_final=True来强制输出最后一个字。

语音端点检测(非实时)

from funasr import AutoModel

model = AutoModel(model="fsmn-vad", model_revision="v2.0.4")

wav_file = f"{model.model_path}/example/asr_example.wav"
res = model.generate(input=wav_file)
print(res)

语音端点检测(实时)

from funasr import AutoModel

chunk_size = 200 # ms
model = AutoModel(model="fsmn-vad", model_revision="v2.0.4")

import soundfile

wav_file = f"{model.model_path}/example/vad_example.wav"
speech, sample_rate = soundfile.read(wav_file)
chunk_stride = int(chunk_size * sample_rate / 1000)

cache = {}
total_chunk_num = int(len((speech)-1)/chunk_stride+1)
for i in range(total_chunk_num):
    speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride]
    is_final = i == total_chunk_num - 1
    res = model.generate(input=speech_chunk, cache=cache, is_final=is_final, chunk_size=chunk_size)
    if len(res[0]["value"]):
        print(res)

标点恢复

from funasr import AutoModel

model = AutoModel(model="ct-punc", model_revision="v2.0.4")

res = model.generate(input="那今天的会就到这里吧 happy new year 明年见")
print(res)

时间戳预测

from funasr import AutoModel

model = AutoModel(model="fa-zh", model_revision="v2.0.4")

wav_file = f"{model.model_path}/example/asr_example.wav"
text_file = f"{model.model_path}/example/text.txt"
res = model.generate(input=(wav_file, text_file), data_type=("sound", "text"))
print(res)

更多详细用法(示例

Benchmark

我们提供Aishell-1数据、内部工业大数据实验中本模型、Paraformer-large-长音频版模型以及kaldi hybrid系统的force-alignment模型的时间戳准确率比较。平均偏移时间(Accumulated averaged shift, AAS)通过计算文本中匹配的token时间戳起始位置相较于人工标注时间戳的相对偏移时间之和的平均值衡量时间戳的准确程度。

Data System AAS(ms)
Aishell-1 Force-alignment 80.1
Paraformer CIF 71.0
Industrial Data Force-alignment 60.3
Paraformer-large CIF2 65.3
Paraformer-FA 69.3

使用方式以及适用范围

运行范围

  • 支持Linux-x86_64,Mac和Windows。

使用方式

  • 直接推理:可以直接通过输入的音频与文字进行时间戳预测,输出与文字序列同步的时间戳。

使用范围与目标场景

  • 适合于离线场景,对不同声学环境中的语音均能够较好的支持,但需要注意输入的文字与语音中的内容不匹配时预测可能会不稳定。

模型局限性以及可能的偏差

考虑到特征提取流程和工具以及训练工具差异,会对AAS的数据带来一定的差异(<0.1%),推理GPU环境差异导致的RTF数值差异。

相关论文以及引用信息

@inproceedings{gao2022paraformer,
  title={Paraformer: Fast and Accurate Parallel Transformer for Non-autoregressive End-to-End Speech Recognition},
  author={Gao, Zhifu and Zhang, Shiliang and McLoughlin, Ian and Yan, Zhijie},
  booktitle={INTERSPEECH},
  year={2022}
}
@inproceedings{Shi2023AchievingTP,
  title={Achieving Timestamp Prediction While Recognizing with Non-Autoregressive End-to-End ASR Model},
  author={Xian Shi and Yanni Chen and Shiliang Zhang and Zhijie Yan},
  booktitle={arXiv preprint arXiv:2301.12343}
  year={2023}
}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论