gcw_mXoV1I2Z/voice-activity-detection
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

pyannote/voice-activity-detection (昇腾 NPU 适配)

语音活动检测(Voice Activity Detection, VAD)模型,基于 pyannote-audio 3.1.1。 本仓库为昇腾 NPU(Ascend910 / torch-npu)适配版,提供 CLI 与 FastAPI 双模式推理。

模型信息

字段值
原始模型pyannote/voice-activity-detection
任务语音活动检测(VAD)
框架PyTorch + pyannote-audio 3.1.1
推理设备npu:0(Ascend 910)
分割子模型pyannote/segmentation(SincNet 架构)

模型输出 params(在 config.yaml 中):

  • onset: 0.8104268538848918
  • offset: 0.4806866463041527
  • min_duration_on: 0.05537587440407595
  • min_duration_off: 0.09791355693027545

昇腾 NPU 适配说明

  1. CUDA 全量清理:所有 CUDA 调用(.cuda() / torch.cuda.* / device="cuda")一律删除,模型与输入张量统一迁移到 npu:0。
  2. NPU 初始化捕获:入口脚本 try: import torch_npu; torch.npu.set_device(0),失败即抛出明确错误。
  3. torchaudio 兼容:torchaudio 2.9 移除 set_audio_backend 且依赖 torchcodec(NPU 环境无 libnvrtc),已对 pyannote.audio 的 core/io.py 打补丁改用 soundfile 读取音频。
  4. 本地权重加载:权重缓存于 ./model_weights/pyannote/voice-activity-detection,Model.from_pretrained(checkpoint=..., hparams_file=...) 本地加载,无需 HF token。

安装依赖

pip install -r requirements.txt

使用方式

CLI 推理

python inference.py --img test_input.wav

输出示例(JSON):

{
  "status": "ok",
  "device": "npu:0",
  "num_speech_segments": 1,
  "segments": [
    {"start": 1.02, "end": 2.98, "duration": 1.96, "label": "SPEECH"}
  ]
}

FastAPI 服务

uvicorn inference:app --host 0.0.0.0 --port 8000

调用:

curl -F "file=@test_input.wav" http://127.0.0.1:8000/predict

返回 JSON:{"status", "device", "num_speech_segments", "segments"}。

文件结构

.
├── inference.py          # CLI + FastAPI 双模式推理脚本
├── requirements.txt      # 依赖声明
├── test_input.wav        # 合成测试音频(6s,1-3s 语音段)
├── model_weights/
│   └── pyannote/voice-activity-detection/
│       ├── config.yaml   # VAD pipeline 配置
│       └── segmentation/ # 分割子模型权重
└── assets/               # 适配验证截图