anning-2026/whisper-bemba-stt
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

AbelZimba/whisper-bemba-stt 昇腾 NPU 部署文档

1. 模型简介

模型名称: AbelZimba/whisper-bemba-stt 模型链接: https://huggingface.co/AbelZimba/whisper-bemba-stt 模型描述: 基于 OpenAI Whisper 的语音转文本(STT)模型,在 Bemba(本巴语)语音数据上微调,输入 16kHz 单声道音频,输出转写文本;对英文等 Whisper 支持语言同样可用。 模型架构: WhisperForConditionalGeneration(encoder-decoder Transformer,12+12 层,d_model=768,80 mel 特征,30s 窗口) 参数规模: ~241.7M(fp32,单分片 model.safetensors 966,995,080 bytes,sha256 校验与 LFS oid 一致) 适配引擎: torch_npu(昇腾 NPU 推理引擎)

标签集合: automatic-speech-recognition / whisper / stt / audio / speech-to-text / NPU / Ascend / torch_npu / model-agent-tagged

2. 环境依赖

依赖项版本说明
torch2.9.0
torch_npu2.9.0.post1昇腾 NPU 推理引擎
transformers4.46.3标准格式加载(WhisperForConditionalGeneration + WhisperProcessor),无需 custom code
librosa>= 0.10音频读取与重采样
fastapi / uvicorn / python-multipart-服务化推理(server.py)

注:本模型为 transformers 标准格式(model.safetensors + config.json + tokenizer.json + preprocessor_config.json),权重与配置放 /tmp/whisper-bemba-stt/。

3. 推理步骤

# 内置示例音频(默认 npu:0)
python inference.py --device npu:0

# 指定音频文件(wav/mp3/flac,自动重采样到 16kHz 单声道)
python inference.py --audio examples/sample.wav --device npu:0

# 纯 CPU 推理(对比验证)
python inference.py --device cpu

推理流程:WhisperProcessor(audio, sampling_rate=16000) 提取 log-mel 特征 → WhisperForConditionalGeneration.generate(input_features) 自回归解码 → batch_decode(skip_special_tokens=True) 得到转写文本。

说明:Whisper 语言 token 表不含 Bemba,该微调模型未使用语言强制 token,直接 generate() 即可(自动语言检测+转写);如需指定英文可传 forced_decoder_ids=processor.get_decoder_prompt_ids(language='english', task='transcribe')。

4. 测试样例及输出结果

以下输出为在昇腾 Ascend 910B4(CANN 8.5.1 + torch_npu 2.9.0.post1 + transformers 4.46.3)上实测获得。

样例 1:示例音频转写(4.6s 英文语音)

命令:

python inference.py --device npu:0

输出:

[加载] 完成: WhisperForConditionalGeneration (241.7M params),耗时 3.86s
[输入] examples/sample.wav(4.60s @16kHz)
[结果] 转写文本: The combination of trumpets, violins and a drumset is quite unusual.
[耗时] 7.28s

结果说明:首次推理含算子编译预热(约 7s),进程内稳态耗时 0.34s/条(4.6s 音频)。转写结果为连贯、语义正确的英文句子,验证了 whisper-bemba-stt 在昇腾 NPU 上的语音识别链路通畅。

样例 2:服务化接口转写

见第 6 节 /asr 实测。

5. Agent 适配截图

Agent 适配流程 NPU 设备调用 模型适配结果

6. 服务化推理

python server.py --port 8000 --device npu:0

接口:

  • GET /health → {"status":"ok","model":"AbelZimba/whisper-bemba-stt","device":"npu:0","loaded":true}
  • POST /asr(multipart:file 音频文件,可选 max_new_tokens)→ 转写文本

实测(服务化):

  • /health → {"status":"ok","model":"AbelZimba/whisper-bemba-stt","device":"npu:0","loaded":true}
  • /asr(sample.wav)→ {"text":"The combination of trumpets, violins and a drumset is quite unusual.","audio_seconds":4.6,"elapsed_s":0.344}

7. 注意事项

  • 模型权重位于 /tmp/whisper-bemba-stt/(966,995,080 bytes,sha256 校验通过),不占用仓库空间,不纳入本仓库
  • 音频要求——16kHz 单声道,单次最长 30s(chunk_length=30);librosa 加载时自动重采样
  • 首帧预热——NPU 首次推理含算子编译,约 7s;服务化场景建议启动后先跑一次预热请求
  • dtype——fp32 与 bf16 均可运行;STT 任务对数值精度敏感,默认使用 float32
  • 大文件务必校验 sha256 与 LFS oid 一致,避免下载损坏导致输出异常