(简体中文|English)
FunASR希望在语音识别的学术研究和工业应用之间架起一座桥梁。通过发布工业级语音识别模型的训练和微调,研究人员和开发人员可以更方便地进行语音识别模型的研究和生产,并推动语音识别生态的发展。让语音识别更有趣!
python>=3.8
torch>=1.13
torchaudio
pip3 install -U funasr
git clone https://github.com/alibaba/FunASR.git && cd FunASR
pip3 install -e ./
如果需要使用工业预训练模型,安装modelscope与huggingface_hub(可选)
pip3 install -U modelscope huggingface huggingface_hub
FunASR开源了大量在工业数据上预训练模型,您可以在模型许可协议下自由使用、复制、修改和分享FunASR模型,下面列举代表性的模型,更多模型请参考 模型仓库。
(注:⭐ 表示ModelScope模型仓库,🤗 表示Huggingface模型仓库,🍀表示OpenAI模型仓库)
模型名字 | 任务详情 | 训练数据 | 参数量 |
---|---|---|---|
SenseVoiceSmall (⭐ 🤗 ) |
多种语音理解能力,涵盖了自动语音识别(ASR)、语言识别(LID)、情感识别(SER)以及音频事件检测(AED) | 400000小时,中文 | 330M |
paraformer-zh (⭐ 🤗 ) |
语音识别,带时间戳输出,非实时 | 60000小时,中文 | 220M |
paraformer-zh-streaming ( ⭐ 🤗 ) |
语音识别,实时 | 60000小时,中文 | 220M |
paraformer-en ( ⭐ 🤗 ) |
语音识别,非实时 | 50000小时,英文 | 220M |
conformer-en ( ⭐ 🤗 ) |
语音识别,非实时 | 50000小时,英文 | 220M |
ct-punc ( ⭐ 🤗 ) |
标点恢复 | 100M,中文与英文 | 290M |
fsmn-vad ( ⭐ 🤗 ) |
语音端点检测,实时 | 5000小时,中文与英文 | 0.4M |
fsmn-kws ( ⭐ ) |
语音唤醒,实时 | 5000小时,中文 | 0.7M |
fa-zh ( ⭐ 🤗 ) |
字级别时间戳预测 | 50000小时,中文 | 38M |
cam++ ( ⭐ 🤗 ) |
说话人确认/分割 | 5000小时 | 7.2M |
Whisper-large-v3 (⭐ 🍀 ) |
语音识别,带时间戳输出,非实时 | 多语言 | 1550 M |
Whisper-large-v3-turbo (⭐ 🍀 ) |
语音识别,带时间戳输出,非实时 | 多语言 | 809 M |
Qwen-Audio (⭐ 🤗 ) |
音频文本多模态大模型(预训练) | 多语言 | 8B |
Qwen-Audio-Chat (⭐ 🤗 ) |
音频文本多模态大模型(chat版本) | 多语言 | 8B |
emotion2vec+large (⭐ 🤗 ) |
情感识别模型 | 40000小时,4种情感类别 | 300M |
funasr ++model=paraformer-zh ++vad_model="fsmn-vad" ++punc_model="ct-punc" ++input=asr_example_zh.wav
注:支持单条音频文件识别,也支持文件列表,列表为kaldi风格wav.scp:wav_id wav_path
from funasr import AutoModel
from funasr.utils.postprocess_utils import rich_transcription_postprocess
model_dir = "iic/SenseVoiceSmall"
model = AutoModel(
model=model_dir,
vad_model="fsmn-vad",
vad_kwargs={"max_single_segment_time": 30000},
device="cuda:0",
)
# en
res = model.generate(
input=f"{model.model_path}/example/en.mp3",
cache={},
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
use_itn=True,
batch_size_s=60,
merge_vad=True, #
merge_length_s=15,
)
text = rich_transcription_postprocess(res[0]["text"])
print(text)
参数说明:
model_dir
:模型名称,或本地磁盘中的模型路径。vad_model
:表示开启VAD,VAD的作用是将长音频切割成短音频,此时推理耗时包括了VAD与SenseVoice总耗时,为链路耗时,如果需要单独测试SenseVoice模型耗时,可以关闭VAD模型。vad_kwargs
:表示VAD模型配置,max_single_segment_time
: 表示vad_model
最大切割音频时长, 单位是毫秒ms。use_itn
:输出结果中是否包含标点与逆文本正则化。batch_size_s
表示采用动态batch,batch中总音频时长,单位为秒s。merge_vad
:是否将 vad 模型切割的短音频碎片合成,合并后长度为merge_length_s
,单位为秒s。ban_emo_unk
:禁用emo_unk标签,禁用后所有的句子都会被赋与情感标签。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", vad_model="fsmn-vad", punc_model="ct-punc",
# spk_model="cam++"
)
res = model.generate(input=f"{model.model_path}/example/asr_example.wav",
batch_size_s=300,
hotword='魔搭')
print(res)
注: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")
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")
wav_file = f"{model.model_path}/example/vad_example.wav"
res = model.generate(input=wav_file)
print(res)
注:VAD模型输出格式为:[[beg1, end1], [beg2, end2], .., [begN, endN]]
,其中begN/endN
表示第N
个有效音频片段的起始点/结束点,
单位为毫秒。
from funasr import AutoModel
chunk_size = 200 # ms
model = AutoModel(model="fsmn-vad")
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)
注:流式VAD模型输出格式为4种情况:
[[beg1, end1], [beg2, end2], .., [begN, endN]]
:同上离线VAD输出结果。[[beg, -1]]
:表示只检测到起始点。[[-1, end]]
:表示只检测到结束点。[]
:表示既没有检测到起始点,也没有检测到结束点
输出结果单位为毫秒,从起始点开始的绝对时间。from funasr import AutoModel
model = AutoModel(model="ct-punc")
res = model.generate(input="那今天的会就到这里吧 happy new year 明年见")
print(res)
from funasr import AutoModel
model = AutoModel(model="fa-zh")
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)
from funasr import AutoModel
model = AutoModel(model="emotion2vec_plus_large")
wav_file = f"{model.model_path}/example/test.wav"
res = model.generate(wav_file, output_dir="./outputs", granularity="utterance", extract_embedding=False)
print(res)
funasr-export ++model=paraformer ++quantize=false
from funasr import AutoModel
model = AutoModel(model="paraformer")
res = model.export(quantize=False)
# pip3 install -U funasr-onnx
from funasr_onnx import Paraformer
model_dir = "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch"
model = Paraformer(model_dir, batch_size=1, quantize=True)
wav_path = ['~/.cache/modelscope/hub/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/example/asr_example.wav']
result = model(wav_path)
print(result)
更多例子请参考 样例
FunASR支持预训练或者进一步微调的模型进行服务部署。目前支持以下几种服务部署:
详细信息可以参阅(服务部署文档)。
如果您在使用中遇到问题,可以直接在github页面提Issues。欢迎语音兴趣爱好者扫描以下的钉钉群二维码加入社区群,进行交流和讨论。
钉钉群 |
---|
贡献者名单请参考(致谢名单)
项目遵循The MIT License开源协议,模型许可协议请参考(模型协议)
@inproceedings{gao2023funasr,
author={Zhifu Gao and Zerui Li and Jiaming Wang and Haoneng Luo and Xian Shi and Mengzhe Chen and Yabin Li and Lingyun Zuo and Zhihao Du and Zhangyu Xiao and Shiliang Zhang},
title={FunASR: A Fundamental End-to-End Speech Recognition Toolkit},
year={2023},
booktitle={INTERSPEECH},
}
@inproceedings{An2023bat,
author={Keyu An and Xian Shi and Shiliang Zhang},
title={BAT: Boundary aware transducer for memory-efficient and low-latency ASR},
year={2023},
booktitle={INTERSPEECH},
}
@inproceedings{gao22b_interspeech,
author={Zhifu Gao and ShiLiang Zhang and Ian McLoughlin and Zhijie Yan},
title={{Paraformer: Fast and Accurate Parallel Transformer for Non-autoregressive End-to-End Speech Recognition}},
year=2022,
booktitle={Proc. Interspeech 2022},
pages={2063--2067},
doi={10.21437/Interspeech.2022-9996}
}
@article{shi2023seaco,
author={Xian Shi and Yexin Yang and Zerui Li and Yanni Chen and Zhifu Gao and Shiliang Zhang},
title={{SeACo-Paraformer: A Non-Autoregressive ASR System with Flexible and Effective Hotword Customization Ability}},
year=2023,
journal={arXiv preprint arXiv:2308.03266(accepted by ICASSP2024)},
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。