File size: 9,876 Bytes
5ce9532 bc8e2a9 83a48f4 cf3f460 bc8e2a9 83a48f4 cf3f460 bc8e2a9 5b6d058 bc8e2a9 5ce9532 bc8e2a9 5b6d058 bc8e2a9 9a6be16 bc8e2a9 83a48f4 cf3f460 83a48f4 bc8e2a9 5083ef1 bc8e2a9 5b6d058 bc8e2a9 5b6d058 bc8e2a9 9a6be16 bc8e2a9 73357a5 bc8e2a9 5b6d058 bc8e2a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | ---
tags:
- automatic-speech-recognition
- audio
- asr
- onnx
- onnxruntime
- quantized
- int8
- int4
- english
- chinese
- cantonese
- french
- japanese
- german
- korean
language:
- en
- zh
- yue
- fr
- ja
- de
- ko
library_name: onnx
pipeline_tag: automatic-speech-recognition
license: cc-by-nc-4.0
repository: https://github.com/AutoArk/open-audio-opd
---
<div align="center">
# Audio8-ASR-0.1B ONNX Runtime
[](https://github.com/AutoArk/open-audio-opd)
[](https://arxiv.org/abs/2605.28139)
[](https://creativecommons.org/licenses/by-nc/4.0/)
</div>
Audio8-ASR-0.1B ONNX Runtime is a self-contained local inference package for
multilingual automatic speech recognition. It includes ONNX Runtime inference code,
a browser UI, a local HTTP API, tokenizer/config files, and decoder/audio-head
precision variants.
The model is a multilingual ASR model with support for English, Chinese,
Cantonese, French, Japanese, German, and Korean.
This repository does not require the original training repository or a separate
source checkpoint at runtime. Everything needed for CPU ONNX inference is in
`model_bundle/`.
This repository is intended to be used through the included ONNX Runtime code.
It is not a Transformers `AutoModel` source release.
The root `config.json` is included for Hugging Face Hub metadata and download
accounting. Runtime graph metadata is stored in `model_bundle/metadata.json`.
## Related Repositories
- [Audio8-ASR-0.1B](https://huggingface.co/AutoArk-AI/Audio8-ASR-0.1B): main model repository.
- [Audio8-ASR-0.1B-iOS-ANE](https://huggingface.co/AutoArk-AI/Audio8-ASR-0.1B-iOS-ANE): iPhone-ready, out-of-the-box ASR demo and Swift SDK. The demo is designed to keep runtime memory footprint around 200 MB on device.
- [AutoArk/open-audio-opd](https://github.com/AutoArk/open-audio-opd): shared GitHub project for Audio8 public releases.
## Contents
- `model_bundle/`: tokenizer, feature extractor config, ONNX graphs, and numpy weights.
- `asr_onnx_runtime.py`: ONNX Runtime ASR engine.
- `server.py`: FastAPI local web/API server.
- `static/`: browser UI with file upload, microphone recording, precision switching, hotwords, and memory panels.
- `transcribe_file.py`: single-file CLI and minimal Python helper.
- `hotword/`: optional decode-time hotword trie boosting helper.
- `run_local.sh`: local WebUI launch helper.
- `smoke_test.sh`: health + ASR API smoke test for a user-provided audio file.
- `measure_precision_memory.py`: optional fresh-process RSS measurement helper.
## Included ONNX Variants
Decoder cache graphs:
- `fp32`: `lm_cache_prefill.onnx`, `lm_cache_decode.onnx`
- `int8`: `lm_cache_prefill_int8.onnx`, `lm_cache_decode_int8.onnx`
- `int4`: `lm_cache_prefill_int4.onnx`, `lm_cache_decode_int4.onnx`
Audio tower graphs:
- `fp32`: `audio_hidden.onnx`
- `int8`: `audio_hidden_int8.onnx`
The default runtime path is decoder `int8` plus audio tower `int8`. Decoder
`int4` is included for lower peak memory, while decoder `fp32` is included as a
full-precision reference path.
## Install
Use Python 3.10+. Python 3.12 is recommended.
```bash
python3.12 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-onnx.txt
```
With `uv`:
```bash
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python -r requirements-onnx.txt
source .venv/bin/activate
```
With conda:
```bash
conda create -n audio8-asr-onnx python=3.12
conda activate audio8-asr-onnx
python3 -m pip install -r requirements-onnx.txt
```
## Run WebUI
```bash
./run_local.sh
```
Open:
```text
http://127.0.0.1:7860
```
If the port is busy:
```bash
PORT=7870 ./run_local.sh
```
## Command Line
Transcribe one local audio file without starting the WebUI:
```bash
python3 transcribe_file.py /path/to/audio.wav --max_new_tokens 128
```
Print the full result JSON:
```bash
python3 transcribe_file.py /path/to/audio.wav --json
```
Force a precision combination:
```bash
python3 transcribe_file.py /path/to/audio.wav \
--cache_precision int8 \
--audio_precision int8
```
Enable optional hotword biasing:
```bash
python3 transcribe_file.py /path/to/audio.wav \
--hotwords "term_one,term_two" \
--json
```
## Use From Python
```python
from pathlib import Path
from asr_onnx_runtime import OnnxCacheAsrEngine
engine = OnnxCacheAsrEngine(
"model_bundle",
cache_precision="int8",
audio_precision="int8",
)
result = engine.transcribe(
Path("/path/to/audio.wav").read_bytes(),
language=None,
max_new_tokens=128,
hotwords=None,
)
print(result["text"])
```
The lower-level `OnnxAsrEngine` class is available for the full-context
fallback graph. Prefer `OnnxCacheAsrEngine` for normal local inference.
## HTTP API
Start the server with `./run_local.sh`, then call `POST /asr` with multipart
form data:
```bash
curl --noproxy "*" -fsS -X POST http://127.0.0.1:7860/asr \
-F "audio=@/path/to/audio.wav" \
-F "max_new_tokens=128" \
-F "cache_precision=int8" \
-F "audio_precision=int8" \
| python3 -m json.tool
```
Form fields:
- `audio`: required audio file. WAV is recommended; `librosa`/`soundfile` handle common formats.
- `language`: optional compatibility field. The current ONNX runtime ignores
this value and lets the model infer the spoken language from audio.
- `max_new_tokens`: optional generation cap; default is `128`.
- `cache_precision`: optional decoder precision, one of `fp32`, `int8`, `int4`, `auto`.
- `audio_precision`: optional audio tower precision, one of `fp32`, `int8`, `auto`.
- `hotwords`: optional comma-separated hotwords. Omit or leave empty to disable.
- `hotword_topk`: optional top-k gate for applying boosts; default is `50`.
- `hotword_start_boost`: optional first-token boost; default is `6.0`.
- `hotword_continuation_boost`: optional continuation-token boost; default is `8.0`.
Useful endpoints:
- `GET /health`: readiness and selected runtime.
- `GET /api/runtime`: selected graphs, provider, and available precision variants.
- `POST /api/reload`: switch backend/precision without restarting the process.
- `GET /metrics`: process/system memory metrics plus runtime info.
Important response fields:
- `text`: normalized transcript for application use.
- `raw`: raw decoded model text before normalization.
- `elapsed_seconds`: inference time inside the runtime.
- `audio_seconds`: decoded audio duration after loading/resampling.
- `generated_tokens`, `hit_stop`, `stop_token_id`: generation diagnostics.
- `backend`, `cache_precision`, `audio_precision`, `providers`: selected runtime path.
- `request_peak_rss_bytes`: latest request RSS high-water mark.
- `hotword`: hotword tokenization/boost metadata when hotwords are enabled, otherwise `null`.
## Hotwords
Hotwords are an opt-in decode-time feature. They do not change model weights,
ONNX graphs, or the prompt. The runtime tokenizes each hotword with the bundled
tokenizer, builds a prefix trie, and adds a top-k gated logit boost during
decoding. If no hotwords are provided, the decode path is unchanged except that
the response includes `"hotword": null`.
The WebUI exposes two hotword strength levels:
- `Normal`: default logit boost.
- `Strong`: stronger biasing for difficult names or rare terms.
Strong hotword biasing may force incorrect hotwords, hallucinate, or repeat
text. Use it only when the target terms are known in advance.
## Runtime Defaults
```text
ASR_BACKEND=auto
ASR_CACHE_PRECISION=int8
ASR_AUDIO_PRECISION=int8
```
Available variants:
- decoder: `fp32`, `int8`, `int4`
- audio tower: `fp32`, `int8`
Force a specific combination:
```bash
ASR_BACKEND=onnx_cache ASR_CACHE_PRECISION=fp32 ASR_AUDIO_PRECISION=fp32 ./run_local.sh
ASR_BACKEND=onnx_cache ASR_CACHE_PRECISION=int8 ASR_AUDIO_PRECISION=int8 ./run_local.sh
ASR_BACKEND=onnx_cache ASR_CACHE_PRECISION=int4 ASR_AUDIO_PRECISION=int8 ./run_local.sh
```
## Runtime Limits
- Audio is loaded as mono and resampled to 16 kHz.
- Audio longer than 30 seconds is truncated by the runtime bundle metadata.
- Cached decoder context is capped at 512 total tokens. If prompt audio tokens
plus `max_new_tokens` exceed that limit, the runtime raises an error.
- CPU ONNX Runtime is the verified default path. GPU use requires installing a
compatible ONNX Runtime GPU package and selecting an available provider.
## License
This project is released under the Creative Commons Attribution-NonCommercial
4.0 International License (CC BY-NC 4.0). Commercial use is not permitted under
this license. See `LICENSE`.
## Notes
- `requirements-onnx.txt` is pinned for reproducible local behavior.
- Runtime audio loading tries `librosa.load` first for consistent decoding.
- `run_local.sh` sets `NO_PROXY/no_proxy` for localhost inside the service
process only; it does not change system proxy settings.
- Browser recording uploads WAV/RIFF audio. The UI records PCM with Web Audio,
waits a short flush after Stop, then appends silence before encoding WAV.
- The UI memory panels report process RSS for CPU ONNX inference. `Peak RSS` is
the service high-water mark; `Request Peak` is the latest request peak.
## Quick Checks
Syntax/import check:
```bash
python3 -m py_compile \
asr_onnx_runtime.py \
server.py \
measure_precision_memory.py \
transcribe_file.py
```
API smoke test with your own audio file:
```bash
./run_local.sh
./smoke_test.sh 127.0.0.1 7860 /path/to/audio.wav
```
Run one precision memory measurement:
```bash
python3 measure_precision_memory.py \
--bundle_dir model_bundle \
--audio /path/to/audio.wav \
--cache_precision int8 \
--audio_precision int8
```
|