当前位置: 首页 > news >正文

FunASR 快速上手

本文摘抄自 FunASR 项目的官方 Markdown 文件

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 AutoModelchunk_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-attentionmodel = AutoModel(model="paraformer-zh-streaming", model_revision="v2.0.4")import soundfile
import oswav_file = os.path.join(model.model_path, "example/asr_example.wav")
speech, sample_rate = soundfile.read(wav_file)
chunk_stride = chunk_size[1] * 960 # 600mscache = {}
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 - 1res = 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 AutoModelmodel = 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 AutoModelchunk_size = 200 # ms
model = AutoModel(model="fsmn-vad", model_revision="v2.0.4")import soundfilewav_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 - 1res = 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 AutoModelmodel = AutoModel(model="ct-punc", model_revision="v2.0.4")res = model.generate(input="那今天的会就到这里吧 happy new year 明年见")
print(res)

时间戳预测

from funasr import AutoModelmodel = 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)

更多详细用法(示例)

http://www.jsqmd.com/news/43134/

相关文章:

  • JDBC与MySQL交互有哪些安全措施
  • 网络分析模型八
  • java执行linux 命令
  • 主机开v*n 虚拟机共享v*n
  • 2025-11-18 vue3+ts项目报错:TypeError: Failed to fetch dynamically imported==》script没有指定使用lang=ts
  • 2025 年 11 月新风系统厂家推荐排行榜,沈阳/大连/鞍山/哈尔滨/内蒙古,电竞网咖/酒店/棋牌室/KTV/别墅/学校/诊所/养殖基地,全热交换/除湿/加湿/静音/防冷凝水/节能/耐用/口碑好
  • 2025 年 11 月无尘投料站厂家推荐排行榜,自动无尘投料站,真空无尘投料站,吨袋无尘投料站,高效无尘投料站公司推荐
  • alpha阶段工作总结11.17
  • 绘图区右键上下文菜单快捷键设置
  • javac linux
  • java 调用linux命令
  • 西门子v4.0问题
  • java 读取文件linux文件
  • java 读取linux 文件
  • java 上传 linux
  • 从接雨水问题看双指针与递归:藏在“收缩”里的分治智慧
  • Day22综合案例一:
  • 获取抗菌-抗癌-抗炎-抗氧化序列
  • LDO(线性稳压器)-理论篇
  • Tauri2.9+Vue3电脑端OS系统|vite7+tauri2+arcoDesign桌面os后台模板
  • 黑马程序员SpringCloud微服务开发与实战- Docker-01
  • 11-17午夜盘思
  • 葫芦娃,要远离小心毒蛇和蝎子。
  • 6.S081 操作系统 Lab1
  • Coco AI 参选 Gitee 2025 最受欢迎开源软件!您的每一票,都是对中国开源的硬核支持
  • 题解:P14002 [eJOI 2025] Navigation
  • 多媒体与可视化:WebAssembly集成与实时视频贴图
  • 第三章作业 动态规划
  • Java Room与SQLite如何交互
  • 11月17日日记