Qwen3-ForcedAligner-0.6B 是通义千问推出的强制对齐(Forced Alignment)模型,支持对 11 种语言的语音-文本对进行字/词级时间戳预测。该模型可在最长 5 分钟的音频上进行精确的对齐预测,精度超越现有的 E2E 强制对齐模型(如 NFA、WhisperX)。
本仓库提供基于 Ascend NPU 的适配方案,支持在华为昇腾设备上使用 torch_npu + transformers 后端进行推理。
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0rc1 |
vllm | 0.18.0+empty |
transformers | 4.57.6 |
torch-npu | 2.9.0.post1+gitee7ba04 |
qwen-asr | 0.0.6 |
1 逻辑卡(Atlas 800 A2)Linux 5.10.0 aarch643.11.14pip install qwen-asrForcedAligner 与 ASR 模型共享同一架构 Qwen3ASRForConditionalGeneration,加载前需注册自定义模型类:
from qwen_asr.core.transformers_backend.configuration_qwen3_asr import Qwen3ASRConfig
from qwen_asr.core.transformers_backend.modeling_qwen3_asr import Qwen3ASRForConditionalGeneration
from qwen_asr.core.transformers_backend.processing_qwen3_asr import Qwen3ASRProcessor
from transformers import AutoConfig, AutoModel, AutoProcessor
AutoConfig.register("qwen3_asr", Qwen3ASRConfig)
AutoModel.register(Qwen3ASRConfig, Qwen3ASRForConditionalGeneration)
AutoProcessor.register(Qwen3ASRConfig, Qwen3ASRProcessor)使用 Qwen3ForcedAligner 封装类:
import torch
import torch_npu
from qwen_asr import Qwen3ForcedAligner
model = Qwen3ForcedAligner.from_pretrained(
"/path/to/Qwen3-ForcedAligner-0.6B",
dtype=torch.bfloat16,
attn_implementation="eager",
device_map=None,
)
model.model = model.model.to("npu:0")
results = model.align(
audio="audio.wav",
text="甚至出现交易几乎停滞的情况。",
language="Chinese",
)
for item in results[0]:
print(f"{item.text}: {item.start_time}s - {item.end_time}s")python inference.py --audio test_audio_zh.wav --text "甚至出现交易几乎停滞的情况。" --language Chinese
python inference.py --audio test_audio_en.wav --text "Hmm. Oh yeah, yeah." --language English| 样本 | 语言 | 时长 | 对齐文本 |
|---|---|---|---|
| test_audio_zh.wav | 中文 | 4.20秒 | 甚至出现交易几乎停滞的情况。(13字符) |
| test_audio_en.wav | 英文 | 15.05秒 | Hmm. Oh yeah, yeah...(36词) |
中文时间戳(13字符):
| 字 | 开始时间 | 结束时间 |
|---|---|---|
| 甚 | 0.400秒 | 0.720秒 |
| 至 | 0.720秒 | 0.960秒 |
| 出 | 0.960秒 | 1.120秒 |
| 现 | 1.120秒 | 1.520秒 |
| 交 | 1.520秒 | 1.760秒 |
| 易 | 1.760秒 | 2.000秒 |
| 几 | 2.000秒 | 2.240秒 |
| 乎 | 2.240秒 | 2.480秒 |
| 停 | 2.480秒 | 2.720秒 |
| 滞 | 2.720秒 | 2.880秒 |
| 的 | 2.880秒 | 3.040秒 |
| 情 | 3.040秒 | 3.360秒 |
| 况 | 3.360秒 | 3.680秒 |
英文时间戳(前5词):
| 词 | 开始时间 | 结束时间 |
|---|---|---|
| Hmm | 0.480秒 | 0.880秒 |
| Oh | 1.040秒 | 1.280秒 |
| yeah | 1.280秒 | 1.520秒 |
| yeah | 1.520秒 | 1.920秒 |
| He | 2.320秒 | 2.400秒 |
所有时间戳均在音频时长范围内,单调递增且不重叠。
| 语言 | 音频时长 | Token数 | 平均延迟 | P50 | P95 | 吞吐量 |
|---|---|---|---|---|---|---|
| 中文 | 4.20秒 | 13 | 0.097秒 | 0.097秒 | 0.098秒 | 10.27 样本/秒 |
| 英文 | 15.05秒 | 36 | 0.130秒 | 0.130秒 | 0.130秒 | 7.70 样本/秒 |
中文、英文、粤语、法语、德语、意大利语、日语、韩语、葡萄牙语、俄语、西班牙语