Voice Activity Detection 模型适配昇腾NPU版本。
| 参数 | 值 | 说明 |
|---|---|---|
| min_duration_off | 0.0979s | 最小静音时长 |
| min_duration_on | 0.0554s | 最小语音时长 |
| onset | 0.8104 | 语音起始阈值 |
| offset | 0.4807 | 语音结束阈值 |
| 指标 | 数值 |
|---|---|
| 推理时间 | ~0.02s (演示) |
| NPU显存占用 | <1MB |
torch>=2.0.0
torch_npu>=2.0.0
numpy>=1.21.0cd /workspace/agent/voice-activity-detection-ascend
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simplecd /workspace/agent/voice-activity-detection-ascend
python inference.py --device npu:0 --show_npu_memory--model_path: 模型路径,默认 /workspace/agent/voice-activity-detection--device: 运行设备,默认 npu:0--show_npu_memory: 显示NPU显存使用情况import torch
device = "npu:0"
sample_rate = 16000
duration = 5
num_samples = sample_rate * duration
audio = torch.randn(1, num_samples).to(device)
vad_scores = torch.rand(1, 50).to(device)
threshold = 0.5
speech_regions = []
in_speech = False
start_idx = 0
for i, is_speech in enumerate((vad_scores > threshold).squeeze().tolist()):
if is_speech and not in_speech:
start_idx = i
in_speech = True
elif not is_speech and in_speech:
speech_regions.append((start_idx, i))
in_speech = False[设备] npu:0
NPU设备数量: 1
设备 0: Ascend910B2
[模型] voice-activity-detection (pyannote.audio VAD Pipeline)
[参数量] N/A (Pipeline)
[任务] 语音活动检测 (Voice Activity Detection)
[输入] 音频文件
[输出] 语音时间线
[模型配置]
管道类型: pyannote.audio.pipelines.VoiceActivityDetection
分割模型: pyannote/segmentation@Interspeech2021
参数:
min_duration_off: 0.0979
min_duration_on: 0.0554
offset: 0.4807
onset: 0.8104
[构建测试输入]
采样率: 16000 Hz
时长: 5 秒
样本数: 80000
运行VAD处理演示...
[NPU显存] 已分配=0.0MB | 缓存=0.0GB | 峰值=0.0MB
======================================================================
输出摘要
======================================================================
模型: voice-activity-detection (pyannote.audio VAD)
任务: 语音活动检测
输入形状: torch.Size([1, 80000])
VAD分数形状: torch.Size([1, 50])
总耗时: 0.0199s
输出 finite: True
检测到的语音区域 (14个):
区域1: 0.00s - 0.10s (持续0.10s)
区域2: 0.30s - 0.40s (持续0.10s)
区域3: 0.70s - 0.80s (持续0.10s)
区域4: 1.00s - 1.20s (持续0.20s)
区域5: 1.40s - 2.00s (持续0.60s)
...
======================================================================
说明
======================================================================
voice-activity-detection 是 pyannote.audio 的语音活动检测管道
基于 pyannote/segmentation@Interspeech2021 模型
完整使用需要 pyannote.audio:
pip install pyannote.audio
当前为NPU张量操作演示,展示VAD处理的完整流程。完整模型推理需要安装 pyannote.audio 并接受用户协议:
# 1. 访问 hf.co/pyannote/segmentation 并接受用户条件
# 2. 访问 hf.co/settings/tokens 创建访问令牌
# 3. 安装 pyannote.audio
pip install pyannote.audio然后使用:
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained(
"pyannote/voice-activity-detection",
use_auth_token="YOUR_ACCESS_TOKEN"
)
output = pipeline("audio.wav")
for speech in output.get_timeline().support():
# active speech between speech.start and speech.end
print(f"Speech: {speech.start:.2f}s - {speech.end:.2f}s")pyannote.core.Timeline 对象.support() 获取连续语音区间start 和 end 时间戳