--- language: [fa] license: gpl-3.0 library_name: onnx pipeline_tag: voice-activity-detection tags: [persian, farsi, speaker-diarization, onnx, coreml, shenava, zipformer] base_model: Reza2kn/Shenava-Rizeh-v1.6 --- # Shenava Diarization (for Rizeh v1.6) Who spoke when, for up to 4 speakers, running on top of the [Shenava Rizeh v1.6](https://huggingface.co/Reza2kn/Shenava-Rizeh-v1.6) speech recognizer. The speaker head has **3.5M parameters**. It reads Rizeh's own early encoder layers (the embedding plus stacks 0–1, where speaker identity is still present). With `encoder_spk`, one encoder pass gives you both the transcript and the speaker features, so ASR plus diarization is about 63M parameters instead of the roughly 160M you'd get by adding a 100M diarizer. ## Files | File | What it is | Params | |---|---|---| | `encoder_spk.onnx` / `.int8.onnx` | The Rizeh v1.6 offline encoder with a 3rd output, `spk_feats` (1, T, 640) at 50 Hz. It drops into sherpa-onnx in place of `encoder.onnx`: same `encoder_out`, identical transcripts on 30/30 test clips. | 0 extra | | `frontend.onnx` / `.int8.onnx` | Only embed + stack 0 + stack 1 → `spk_feats`, for diarization without running ASR | 6.6M | | `head.onnx` / `.int8.onnx` | `spk_feats` (1, T, 640) → `probs` (1, ⌈T/2⌉, 4): per-speaker activity every 40 ms, speakers numbered by order of first appearance | 3.5M | | `coreml/encoder_spk.mlpackage`, `coreml/frontend.mlpackage` | iOS 16+, fp16 with fp32 reductions, 30 s window plus `x_lens` (same padding-safe graph as the CoreML-fp16 ASR repo) | | | `coreml/head.mlpackage` | iOS 16+, flexible length up to 4096 feature frames | | | `diarize.py` | Reference runner: numpy fbank (an exact port of Rizeh's front end) + onnxruntime + the speaker cache | | ## Long audio: the speaker cache The head is trained on 40 s windows. For longer recordings, `diarize.py` processes 40 s chunks (30 s with the CoreML window). In front of each chunk it places a cache: the most confident few seconds (8 s) of every speaker heard so far, in the order they first spoke. Because the head numbers speakers by first appearance, a cached speaker keeps their number, and a new voice gets the next free one. The cache is rebuilt from each chunk's confident single-speaker frames. ```bash pip install onnxruntime numpy soundfile python diarize.py talk.wav # start end speaker_k python diarize.py talk.wav --rttm talk.rttm python diarize.py show.wav --gap 2 # broadcast style: fill pauses < 2 s inside a turn python diarize.py talk.wav --int8 ``` If your app already runs `encoder_spk` for ASR, pass its `spk_feats` to `Diarizer.step()` and skip `frontend`. ## Accuracy Frame-level DER, no collar, every speaker counted. Lower is better. | Test | This model | Notes | |---|---|---| | Long conversations: 16 recordings, 3–7 min, 2–4 Persian Common Voice speakers never seen in training (`diarize.py`, fp32) | **9.7%** (speaker count right 11/16) | int8: 9.8%. Without the cache: 46% | | Real phone and call-in conversations (80 held-out windows; scored against nvidia/Nemotron-3-Diarization labels) | 7.5% (count right 73/80) | | | Simulated conversations, ≤ 90 s, 24 streams | 7.6–8.1% | Nemotron-3-Diarization (100M) scores 21.2% here | | Golha radio programs, first 90 s, fill gaps < 2 s | 26.6% | Nemotron-3: 33.8%. Golha's labels are coarse and count singers as speakers | Speed: 108× real time on CPU (onnxruntime, 4 threads, frontend + head). On an M2 with CoreML on the GPU: 63 ms per 30 s for `encoder_spk`, plus 6 ms for the head. ## Limits - Up to **4 speakers per recording**. A recording with 5 or more people (full Golha programs, panels) will merge some of them. - Music: training included instrumental music beds and music-only breaks (MUSAN instrumental tracks plus Persian solo setar). Singing is not treated as a speaker. - The CoreML int4 builds and the Neural Engine aren't supported here: the ANE compiler rejects these graphs, so use CPU+GPU. ## Training Sortformer-style arrival-order BCE loss. Training data: - simulated Persian conversations: 3,535 Common Voice speakers; - 420 real phone and call-in recordings labeled by nvidia/Nemotron-3-Diarization; - music and noise backgrounds; - examples in the cache format above. The Rizeh encoder is frozen; only the head is trained. GPL-3.0-or-later. Built on [dkaraush/tinyasr](https://github.com/dkaraush/tinyasr) (YODAS v3, CC BY 3.0), Mozilla Common Voice (CC0), MUSAN (CC BY 4.0 / mixed: see its license files), and Razavipour/persian-solo-setar.