Speaker Diarization Community-1 是 pyannote.audio 的说话人 diarization 流水线,本项目提供其在华为 Ascend NPU 环境下的部署方案。
/data/ysws/agentsp/speaker-diarization-community-1-ascend/
├── inference.py # 精度测试脚本
├── log.txt # 测试日志
├── README.md # 本文档
├── test_audio_1s.pt # 测试音频 (1秒)
└── test_audio_3s.pt # 测试音频 (3秒)docker exec -it test-modelagent bashsource /usr/local/Ascend/ascend-toolkit/set_env.shcd /data/ysws/agentsp/speaker-diarization-community-1-ascend/
python3 inference.py| 指标 | 实测值 | 阈值 | 状态 |
|---|---|---|---|
| Segmentation Max Error | 1.63e-03 | < 1e-2 | PASS |
| Segmentation Mean Error | 6.19e-04 | < 1e-2 | PASS |
| CPU vs NPU Embeddings | 一致 | < 1% | PASS |
| 操作 | 耗时 |
|---|---|
| Pipeline NPU 推理 (1s 音频) | 6.54s |
完整测试日志保存在 log.txt
| 组件 | 说明 |
|---|---|
| SincNet | 原始音频特征提取 (80 mel bins) |
| BiLSTM | 4层双向LSTM (60→128 hidden) |
| Linear | 帧级别分类 (128→7 classes) |
| 组件 | 说明 |
|---|---|
| ResNet34 | 图像风格CNN特征提取 |
| StatsPool | 时序统计池化 |
| Linear | 说话人嵌入投影 (5120→256) |
| 参数 | 形状 |
|---|---|
| mu | (128,) |
| tr | (128, 128) |
| psi | (128,) |
import torch
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained("/data/ysws/agentsp/speaker-diarization-community-1")
pipeline.to("npu:0")
waveform = torch.randn(1, 16000)
audio = {"waveform": waveform, "sample_rate": 16000}
output = pipeline(audio)
for turn, speaker in output.speaker_diarization:
print(f"{speaker} speaks between t={turn.start:.3f}s and t={turn.end:.3f}s")import torch
from pyannote.audio import Model
seg_model = Model.from_pretrained("/data/ysws/agentsp/speaker-diarization-community-1/segmentation")
seg_model.to("npu:0")
waveform = torch.randn(1, 16000)
output = seg_model(waveform.to("npu:0"))
print(f"Output shape: {output.shape}") # (batch, frames, 7)import torch
from pyannote.audio import Model
emb_model = Model.from_pretrained("/data/ysws/agentsp/speaker-diarization-community-1/embedding")
emb_model.to("npu:0")
waveform = torch.randn(1, 16000)
embedding = emb_model(waveform.to("npu:0"))
print(f"Embedding shape: {embedding.shape}") # (batch, 256)本模型依赖 pyannote.audio 4.0.4,已在容器中预装。关键依赖:
A: 检查 NPU 驱动是否正确安装,确保 CANN 环境变量已 source。
A: pyannote.audio 支持内存中的音频数据,使用 {"waveform": tensor, "sample_rate": 16000} 格式。
A: 使用较短的音频片段进行测试,或使用批量处理。
本项目遵循 pyannote.audio 原始许可证。