--- language: - fa - en license: gpl-3.0 library_name: onnx pipeline_tag: automatic-speech-recognition base_model: - Reza2kn/Shenava-Rizeh-v1.5 base_model_relation: quantized tags: - automatic-speech-recognition - persian - farsi - zipformer - rnnt - transducer - streaming - tract - rust - int4 - int8 - on-device - shenava --- # 🎙️ Shenava-Rizeh-v1.5-tract-streaming A cache-aware **streaming** export of [Shenava Rizeh v1.5](https://huggingface.co/Reza2kn/Shenava-Rizeh-v1.5) (a Zipformer2 RNN-T) that runs in the pure-Rust **[tract](https://github.com/sonos/tract)** engine. Each step consumes **320 ms** of audio and looks back up to 2.56 s. > **Not a drop-in for v1.0.** v1.0 was a single CTC graph. v1.5 is a transducer: an `encoder` step plus a small `decoder`/`joiner` loop. `harness/main.rs` is a complete working example. ## Files and quality All results are on the EVEN half of golden-6669 + FLEURS (2,758 clips), no LM, official TT. The timings are tract, single thread, on a loaded x86 desktop (Stallion), for one 320 ms chunk including the RNN-T loop. | File | Size | Streaming TT (onnxruntime, beam 4) | tract ms / 320 ms chunk | tract tokens = onnxruntime | |---|---|---|---|---| | `encoder.onnx` (fp32) | 228 MB | 5.31 | **24** (RTF 0.08) | ✅ identical | | `encoder.int4.onnx` (MatMulNBits, block 32) | 69 MB | 5.22 | 43 | 1 token differs on the test clip | | `encoder.int8.onnx` (MatMulInteger) | 60 MB | 5.32 | 190 (dynamic activation quant is slow in tract) | ✅ identical | The decoder (5 MB) and joiner (4 MB) are fp32, and the same files are used with every encoder. For reference, the same model **offline** (whole utterance) scores 4.35, and with 640 ms chunks it scores 5.19 (re-export with chunk 32). **Recommendation:** use fp32 if 228 MB is acceptable. Otherwise use int4, which is 3.3× smaller with the same accuracy, at about half the speed. ## Streaming contract - **Features:** 80-dim kaldi fbank (`fbank_torch.py` is a reference implementation; it matches kaldi-native-fbank). Use samples in [-1, 1], povey window, `snip_edges=false`, 20–7600 Hz. - **Steps:** each step feeds `x` (1, 45, 80) and advances 32 frames (a 13-frame overlap). Append about 0.8 s of silence at the end of speech. - **Encoder inputs:** `x` plus 92 caches. `reference/ref5.shapes` lists them in order with dtype and shape. Start every cache at zero. - **Encoder outputs:** `encoder_out` (1, 8, 512) plus the `new_*` caches, in the same order. Feed them back on the next step. **Cast `new_processed_lens` back to i64**: tract returns it as a symbolic TDim (see the harness). - **RNN-T loop:** - `decoder` takes `y` i64 (1, 2), the last two tokens, starting at `[0, 0]`. - `joiner(encoder_out[t], decoder_out)` returns logits over 2080 tokens. - Blank is 0. **Mask ids 32–1055** (the English block) and take the argmax over 0–31 and 1056–2079. - **Output text:** Persian digits and punctuation are already in the output; no ITN is needed. ## Reproduce / verify ```bash # Cargo deps: tract-onnx, tract-core (tested on tract @ Reza2kn/tract 4259abe, i.e. tract main + the NeMo streaming fixes) cargo run --release -- . reference/ref5 encoder.onnx # harness/main.rs as src/main.rs # -> chunks 53 ~24 ms/chunk tokens 57 match_ort true python stream_ref.py . some.wav out/prefix # onnxruntime reference + chunk dump for any wav ``` `export_onnx_streaming.py` (with `static`) and `make_tract_model.py` regenerate every file here from `shenava-rizeh-v1.5.tzf`. The `make_tract_model.py` step runs onnxruntime's pure-ONNX BASIC optimizer, which folds the shape arithmetic that tract's type inference rejects. ## License GPL-3.0, inherited from tinyasr.