本仓库为 pyannote/segmentation-3.0 在华为昇腾 910B (Ascend910_9362, npu:0) 上的适配验证。基于 PyanNet (SincNet 前端 + 4 层双向 LSTM + 2 层线性 + Sigmoid 分类器) 的自包含 PyTorch 实现,通过 torch_npu 在单卡 NPU 上实现端到端 audio → 语音段时间戳 推理。
pytorch_model.bin (17M) — 通过本地 model_cache_pyannote_seg 离线加载,禁止在线下载task.duration=5.0s, max_num_speakers=3, sample_rate=16000, sincnet.stride=10, lstm.hidden=128 x4 bidirectional monolithic, linear.hidden=128 x2asteroid-filterbanks.ParamSincFB) + pyannote.audio VAD 后处理,无 pyannote.audio 依赖onset=0.8104, offset=0.4807, min_duration_on=0.0554s, min_duration_off=0.0979snpu:0 执行,torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362,模型参数 / 输入 waveform / 输出概率张量均在 npu:0torch.load 的 pyannote.* 桩模块以支持 checkpoint 反序列化;同步计时 torch.npu.synchronize() 区分首次编译与稳定推理208000 samples),重采样 torchaudio.functional.resample,shape [1,1,80000] 窗口[[start,end], ...]pip install -r requirements.txt
# CPU
python inference.py --checkpoint pytorch_model.bin --audio audio.wav --output segments.json --device cpu
# NPU
python inference.py --checkpoint pytorch_model.bin --audio audio.wav --output segments.json --device npu:0
# Benchmark (生成 benchmark.jsonl 供 benchmark_model.py)
python inference.py --checkpoint pytorch_model.bin --audio audio.wav --device npu:0 --benchmark --samples 8 --warmup 1 --benchmark-output benchmark.jsonl
python ../scripts/benchmark_model.py benchmark.jsonlmlk.flac (13.00s, 16000Hz, 真实语音含语音/静音段) — 满足“时长覆盖语音与静音两种区域”要求[1.118-2.278, 3.677-4.633, 6.340-8.746, 10.145-12.705][1.101-2.278, 3.677-4.633, 6.340-8.746, 10.145-12.688]segment_count_delta=0, max_timestamp_delta=0.017s (<0.05s), coverage_delta≈0, region_iou=0.994 (>0.99) → PASSfirst_run_latency=100.35ms, stable_mean=67.76ms, p50=50.30ms, RTF=0.0052, frames/s≈12365 → PASSmodel param device npu:0, input npu:0 (1,1,80000), output npu:0 (1,293,3), finite=True

MIT