FunASR 旨在为语音识别领域的学术研究与工业应用搭建桥梁。通过支持工业级语音识别模型的训练与微调,研究人员和开发者能够更便捷地开展语音识别模型的相关研究与生产工作,助力语音识别生态的发展。ASR 因 Fun 而在!
主要特性 | 最新动态 | 安装指南 | 快速入门 | 运行时环境 | 模型库 | 联系方式
pip3 install -U funasr或者从源代码安装
git clone https://github.com/alibaba/FunASR.git && cd FunASR
pip3 install -e ./为预训练模型安装 modelscope(可选)
pip3 install -U modelscopeFunASR 在工业数据上开源了大量预训练模型。您可以在 模型许可协议 下自由使用、复制、修改和分享 FunASR 模型。以下是部分代表性模型,更多模型请参考 模型库。
(注:🤗 代表 Huggingface 模型库链接,⭐ 代表 ModelScope 模型库链接)
| 模型名称 | 任务详情 | 训练数据 | 参数规模 |
|---|---|---|---|
| paraformer-zh (⭐ 🤗 ) | 语音识别,带时间戳,非流式 | 60000 小时,普通话 | 220M |
( ⭐ 🤗 ) | 语音识别,流式 | 60000 小时,普通话 | 220M |
| paraformer-en ( ⭐ 🤗 ) | 语音识别,带时间戳,非流式 | 50000 小时,英语 | 220M |
| conformer-en ( ⭐ 🤗 ) | 语音识别,非流式 | 50000 小时,英语 | 220M |
| ct-punc ( ⭐ 🤗 ) | 标点恢复 | 1 亿字符,中英双语 | 1.1G |
| fsmn-vad ( ⭐ 🤗 ) | 语音活动检测 | 5000 小时,中英双语 | 0.4M |
| fa-zh ( ⭐ 🤗 ) | 时间戳预测 | 5000 小时,普通话 | 38M |
| cam++ ( ⭐ 🤗 ) | 说话人验证/说话人分离 | 5000 小时 | 7.2M |
funasr +model=paraformer-zh +vad_model="fsmn-vad" +punc_model="ct-punc" +input=asr_example_zh.wav注意:支持识别单个音频文件,以及 Kaldi 风格 wav.scp 格式的文件列表:wav_id wav_pat
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)更多示例请参考 文档