fsmn vad model for fasr
Project description
fasr-vad-fsmn
英文文档地址: README_EN.md
FSMN 语音活动检测插件。离线 fsmn 模型通过 funasr_onnx 完成特征处理和
ONNX 推理;插件也提供 fsmn_online 用于流式 VAD。
安装
pip install fasr-vad-fsmn
注册模型
| 注册名 | 类 | 适用场景 |
|---|---|---|
fsmn |
FSMNVad |
离线 VAD,把完整音频切成语音片段 |
fsmn_online |
FSMNVadOnline |
流式 VAD,边接收音频边输出语音块 |
流水线使用
add_pipe() 中除 component、model、batch_size 等流水线参数外,其它
关键字参数会传给 detector 的模型。FSMN 参数可以直接写在 detector pipe 上:
from fasr import AudioPipeline
pipeline = (
AudioPipeline()
.add_pipe(
"detector",
model="fsmn",
max_end_silence_time=600,
speech_noise_thres=0.55,
num_threads=4,
)
.add_pipe("recognizer", model="paraformer")
.add_pipe("sentencizer", model="ct_transformer")
)
常见配置可以这样选:
| 目标 | 写法 | 效果 |
|---|---|---|
| 少切碎句子 | max_end_silence_time=1000 |
句中短暂停顿不容易切开 |
| 降低结束延迟 | max_end_silence_time=300 |
更快结束片段,但句子可能更碎 |
| 噪声环境 | speech_noise_thres=0.7 |
噪声误检更少,但轻声可能漏掉 |
| 轻声或远场 | speech_noise_thres=0.45 |
更容易保留弱语音,但噪声更容易进入片段 |
| 提高 CPU 吞吐 | num_threads=4 或 num_threads=8 |
更多 CPU 并行,CPU 占用也更高 |
| 使用 GPU | device_id=0 |
使用第 0 张 GPU,需要安装 onnxruntime-gpu |
Confection 配置
fasr 配置文件使用 Confection 的 TOML 风格,不是 YAML。
只配置 VAD 模型:
[vad_model]
@vad_models = "fsmn"
max_end_silence_time = 600
speech_noise_thres = 0.55
num_threads = 4
放在流水线里时,模型参数写在
pipeline.pipes.detector.component.model 下:
[pipeline]
@pipelines = "AudioPipeline.v1"
pipe_order = ["detector"]
[pipeline.pipes]
[pipeline.pipes.detector]
@pipes = "thread_pipe"
batch_size = 4
batch_timeout = 0.1
[pipeline.pipes.detector.component]
@components = "detector"
num_threads = 2
max_segment_duration = 30.0
[pipeline.pipes.detector.component.model]
@vad_models = "fsmn"
max_end_silence_time = 600
speech_noise_thres = 0.55
num_threads = 4
单独使用模型
模型实例化时会自动下载并加载权重。
from fasr.config import registry
from fasr.data import AudioSpan, Waveform
model = registry.vad_models.get("fsmn")(
max_end_silence_time=600,
speech_noise_thres=0.55,
)
audio = AudioSpan(waveform=Waveform.from_file("example.wav"), start_ms=0)
segments = model.detect(audio)
for segment in segments:
print(f"{segment.start_ms}ms - {segment.end_ms}ms")
使用本地权重目录:
model.load_checkpoint("/path/to/fsmn-vad")
参数
离线 fsmn 只保留真正影响 funasr_onnx 推理的参数。checkpoint、
cache_dir、endpoint、revision、force_download 等通用参数由基类提供。
| 参数 | 类型 / 范围 | 默认值 | 调大时 | 调小时 | 什么时候改 |
|---|---|---|---|---|---|
sample_rate |
int,建议 16000 |
16000 |
不建议,增加成本 | 不建议,可能损失语音细节 | 通常不要改 |
device_id |
None、-1、"cpu" 或 GPU id |
None |
设置 GPU id 使用 GPU | None / -1 / "cpu" 使用 CPU |
需要低延迟或高并发 |
num_threads |
int >= 0 |
2 |
CPU 推理可能更快,但占用更多核心 | 更省 CPU,但可能变慢 | CPU 部署调优 |
max_end_silence_time |
int >= 0,毫秒 |
500 |
更容忍停顿,片段更完整,结束更晚 | 结束更快,片段更碎 | 句子切太碎或结束太慢 |
speech_noise_thres |
float,0.0 到 1.0 |
0.6 |
更严格,噪声误检少,轻声可能漏掉 | 更敏感,弱语音保留更多,噪声可能进入 | 噪声误检或轻声漏检 |
调参建议
| 现象 | 优先尝试 |
|---|---|
| 一句话被切成很多段 | max_end_silence_time=1000 或 1200 |
| 说完后很久才结束 | max_end_silence_time=300 到 500 |
| 背景噪声被当成语音 | speech_noise_thres=0.7 或 0.8 |
| 轻声、远场说话被漏掉 | speech_noise_thres=0.45 或 0.5 |
| CPU 占用太高 | 降低 num_threads |
| CPU 推理太慢 | 提高 num_threads,或安装 onnxruntime-gpu 并设置 device_id=0 |
fsmn_online 使用 device="cpu" / device="cuda" 选择设备,并额外提供
chunk_size_ms。chunk_size_ms 越小越实时,但调度开销更大;越大吞吐更稳,
但输出更晚。默认 100 ms 适合多数实时场景。
fsmn_online 还支持通过 apply_turn_detection(...) 做实时断句参数更新。
这个接口主要给 websocket 这类长连接会话使用;离线 fsmn 处理的是完整音频,
不需要这类运行时更新接口。
fsmn_online 的运行时调参重点如下:
| 参数 | 默认值 | 调大时 | 调小时 |
|---|---|---|---|
max_end_silence_time / silence_duration_ms |
500 |
断句更保守,不容易过早切断,但最终结果延迟更高 | 断句更快,但更容易把一句话切成多段 |
speech_noise_thres / threshold |
0.6 |
更严格,更抗噪,但可能漏掉轻声语音 | 更敏感,更容易抓到弱语音,但也更容易误触发噪声 |
prefix_padding_ms |
0 |
更不容易截掉句首,但可能带入更多前置噪声 | 片段更紧,但更容易丢掉第一个音节 |
prefix_padding_ms 在 wrapper 层实现:检测到说话开始时,会把输出片段的起点
按设定值向前回退,并在已有缓冲音频范围内做裁剪。
CPU / GPU
默认使用 CPU ONNX Runtime。加载模型时会打印当前使用 CPU 还是 GPU。
GPU 推理:
uv pip install onnxruntime-gpu
model = registry.vad_models.get("fsmn")(device_id=0)
stream_model = registry.vad_models.get("fsmn_online")(device="cuda")
依赖
fasrfunasr-onnxnumpy >= 1.24onnxruntime >= 1.16, < 1.24- Python 3.10-3.12
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fasr_vad_fsmn-0.5.8.tar.gz.
File metadata
- Download URL: fasr_vad_fsmn-0.5.8.tar.gz
- Upload date:
- Size: 3.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e59dc9dac2914dd0edb2d12419927e26ba7b2a020f7b00402a354827f4768c7c
|
|
| MD5 |
3ce01e3bad8f39d3588a8b1552848d99
|
|
| BLAKE2b-256 |
9b26ed9b5acc95f243ac1271f1f1ddc23272422878e6aac06ccff72a257098e9
|
File details
Details for the file fasr_vad_fsmn-0.5.8-py3-none-any.whl.
File metadata
- Download URL: fasr_vad_fsmn-0.5.8-py3-none-any.whl
- Upload date:
- Size: 3.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d1fe1a1c7bdfd3390004946d831f7dc21cbac0d03405e46c4aa63b295a1f20f
|
|
| MD5 |
55819a794055ed9cbe4232a3e7bc228d
|
|
| BLAKE2b-256 |
0ab068c8edf1c4578a9c72f1308c100b806f250de3e21c345bd867ec9d1cb934
|