OpenAI Whisper on Axera
-
目前支持 C++ 和 Python 两种语言
-
预编译模型下载
-
如需自行转换请参考模型转换
- 2026/01/14: 更简单的模型结构,现在只需要encoder和decoder,去掉原来的decoder_main和decoder_loop;支持来自HuggingFace的模型导出
- AX650N
- AX630C
目前支持的模型规模:
- tiny
- base
- small
- medium
- turbo
目前测试过的语言:
- English
- Chinese
- Japanese
- Korean
- Malaysian
如需小语种或者其他大小的模型可能需要自行转换,参考
- 基于 AX650N、AX630C 的设备已预装 Ubuntu22.04
- 链接互联网,确保设备能正常执行
apt install,pip install等指令 - 已验证设备:
- 支持编程语言:
测试环境为Python 3.12,建议使用Miniconda,安装方法参考
cd python
pip3 install -r requirements.txt
参考 https://github.com/AXERA-TECH/pyaxengine 安装 NPU Python API
登陆开发板后
cd python
python3 whisper_cli.py -t tiny --model_path ../models-ax650 -w ../demo.wav --language zh
输出结果
(whisper) root@ax650:/mnt/data/Github/whisper.axera/python# python whisper_cli.py -t tiny -w ../demo.wav
[INFO] Available providers: ['AxEngineExecutionProvider']
{'wav': '../demo.wav', 'model_type': 'tiny', 'model_path': '../models-ax650', 'language': 'zh', 'task': 'transcribe'}
[INFO] Using provider: AxEngineExecutionProvider
[INFO] Chip type: ChipType.MC50
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Engine version: 2.12.0s
[INFO] Model type: 2 (triple core)
[INFO] Compiler version: 5.0 76f70fdc
[INFO] Using provider: AxEngineExecutionProvider
[INFO] Model type: 2 (triple core)
[INFO] Compiler version: 5.0 76f70fdc
ASR result:
擅职出现交易几乎停止的情况
RTF: 0.11406774537746188
运行参数说明:
| 参数名称 | 说明 | 默认值 |
|---|---|---|
| --wav | 输入音频文件 | |
| --model_type/-t | 模型类型, tiny/base/small | |
| --model_path/-p | 模型所在目录 | ../models |
| --language/-l | 识别语言 | zh |
(whisper) root@ax650:/mnt/data/Github/whisper.axera/python# python whisper_svr.py
[INFO] Available providers: ['AxEngineExecutionProvider']
Server started at http://0.0.0.0:8000
测试服务端
python test_svr.py
在 PC 上完成(已在Ubuntu22.04上测试)
安装开发环境:
sudo apt update
sudo apt install build-essential cmake
获取交叉编译工具链: 地址
将交叉编译工具链路径添加到PATH
编译
cd cpp
./download_bsp.sh
# AX650
./build_ax650.sh
# AX630C
./build_ax630c.sh
在 AX650N 设备上执行
./install/ax650/whisper_cli -w ../demo.wav
或
./install/ax650/whisper_cli --model_type small --model_path ../models-ax650 -w ../demo.wav
输出结果
root@ax650:/mnt/qtang/whisper.axera/cpp# ./install/ax650/whisper_cli --wav ../demo.wav --model_type small --model_path ../models/ --language zh
wav_file: ../demo.wav
model_path: ../models-ax650
model_type: tiny
language: zh
Init whisper success, take 0.4360seconds
Result: 甚至出现交易几乎停止的情况
RTF: 0.1166
./install/ax650/whisper_srv --model_type tiny --model_path ../models-ax650 --language zh --port 8080
port: 8080
model_path: ../models-ax650
model_type: tiny
language: zh
[I][ main][ 60]: Initializing server...
[I][ main][ 65]: Init server success
[I][ start][ 32]: Start server at port 8080, POST binary stream to IP:8080/asr
curl命令行测试:
ffmpeg -i demo.wav -f f32le -c:a pcm_f32le - 2>/dev/null | \
curl -X POST 10.126.33.192:8080/asr \
-H "Content-Type: application/octet-stream" \
--data-binary @-
RTF: Real-Time Factor
CPP:
| Models | AX650N | AX630C |
|---|---|---|
| Whisper-Tiny | 0.08 | |
| Whisper-Base | 0.11 | 0.35 |
| Whisper-Small | 0.24 | |
| Whisper-Turbo | 0.48 |
Python:
| Models | AX650N | AX630C |
|---|---|---|
| Whisper-Tiny | 0.12 | |
| Whisper-Base | 0.16 | 0.35 |
| Whisper-Small | 0.50 | |
| Whisper-Turbo | 0.60 |
| Models | AX650N | AX630C |
|---|---|---|
| Whisper-Tiny | 0.24 | |
| Whisper-Base | 0.18 | |
| Whisper-Small | 0.11 | |
| Whisper-Turbo | 0.06 |
若要复现测试结果,请按照以下步骤:
下载数据集:
cd model_convert
bash download_dataset.sh
运行测试脚本:
cd python
conda activate whisper
python test_wer.py -d aishell --gt_path ../model_convert/datasets/ground_truth.txt --model_type tiny
- CMM Stands for Physical memory used by Axera modules like VDEC(Video decoder), VENC(Video encoder), NPU, etc.
Python:
| Models | CMM(MB) | OS(MB) |
|---|---|---|
| Whisper-Tiny | 332 | 512 |
| Whisper-Base | 533 | 644 |
| Whisper-Small | 1106 | 906 |
| Whisper-Turbo | 2065 | 2084 |
C++:
| Models | CMM(MB) | OS(MB) |
|---|---|---|
| Whisper-Tiny | 332 | 31 |
| Whisper-Base | 533 | 54 |
| Whisper-Small | 1106 | 146 |
| Whisper-Turbo | 2065 | 86 |
- Github issues
- QQ 群: 139953715