Update README.md
Browse files
README.md
CHANGED
|
@@ -1,103 +1,115 @@
|
|
| 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 |
-
let
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
// result.probabilities - confirmed speaker probabilities
|
| 72 |
-
// result.tentativeProbabilities - preview (may change)
|
| 73 |
-
}
|
| 74 |
-
}
|
| 75 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|--------|-------|
|
| 81 |
-
| Latency | ~1.04s (7 * 80ms right context + chunk) |
|
| 82 |
-
| DER (AMI) | ~30.8% |
|
| 83 |
-
| RTFx | ~8.2x on Apple Silicon |
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
|
|
|
|
|
|
|
|
|
|
| 89 |
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Sortformer CoreML Models
|
| 3 |
+
|
| 4 |
+
Streaming speaker diarization models converted from NVIDIA's Sortformer to CoreML for Apple Silicon.
|
| 5 |
+
|
| 6 |
+
## Model Variants
|
| 7 |
+
|
| 8 |
+
| Variant | File | Latency | Use Case |
|
| 9 |
+
|---------|------|---------|----------|
|
| 10 |
+
| **Default** | `Sortformer.mlmodelc` | ~1.12s | Low latency streaming |
|
| 11 |
+
| **NVIDIA Low** | `SortformerNvidiaLow.mlmodelc` | ~1.04s | Low latency streaming |
|
| 12 |
+
| **NVIDIA High** | `SortformerNvidiaHigh.mlmodelc` | ~30.4s | Best quality, offline |
|
| 13 |
+
|
| 14 |
+
## Configuration Parameters
|
| 15 |
+
|
| 16 |
+
| Parameter | Default | NVIDIA Low | NVIDIA High |
|
| 17 |
+
|-----------|---------|------------|-------------|
|
| 18 |
+
| chunk_len | 6 | 6 | 340 |
|
| 19 |
+
| chunk_right_context | 7 | 7 | 40 |
|
| 20 |
+
| chunk_left_context | 1 | 1 | 1 |
|
| 21 |
+
| fifo_len | 40 | 188 | 40 |
|
| 22 |
+
| spkcache_len | 188 | 188 | 188 |
|
| 23 |
+
|
| 24 |
+
## Model Input/Output Shapes
|
| 25 |
+
|
| 26 |
+
Combined model (Sortformer.mlmodelc - default config):
|
| 27 |
+
|
| 28 |
+
| Input | Shape | Description |
|
| 29 |
+
|-------|-------|-------------|
|
| 30 |
+
| chunk | [1, 112, 128] | Mel spectrogram features |
|
| 31 |
+
| chunk_lengths | [1] | Actual chunk length |
|
| 32 |
+
| spkcache | [1, 188, 512] | Speaker cache embeddings |
|
| 33 |
+
| spkcache_lengths | [1] | Actual cache length |
|
| 34 |
+
| fifo | [1, 40, 512] | FIFO queue embeddings |
|
| 35 |
+
| fifo_lengths | [1] | Actual FIFO length |
|
| 36 |
+
|
| 37 |
+
| Output | Shape | Description |
|
| 38 |
+
|--------|-------|-------------|
|
| 39 |
+
| speaker_preds | [T, 4] | Speaker probabilities (4 speakers) |
|
| 40 |
+
| chunk_pre_encoder_embs | [T', 512] | Embeddings for state update |
|
| 41 |
+
| chunk_pre_encoder_lengths | [1] | Actual embedding count |
|
| 42 |
+
|
| 43 |
+
## Usage with FluidAudio (Swift)
|
| 44 |
+
|
| 45 |
+
```swift
|
| 46 |
+
import FluidAudio
|
| 47 |
+
|
| 48 |
+
// Initialize with default config (auto-downloads from HuggingFace)
|
| 49 |
+
let diarizer = SortformerDiarizer(config: .default)
|
| 50 |
+
let models = try await SortformerModels.loadFromHuggingFace(config: .default)
|
| 51 |
+
diarizer.initialize(models: models)
|
| 52 |
+
|
| 53 |
+
// Streaming processing
|
| 54 |
+
for audioChunk in audioStream {
|
| 55 |
+
if let result = try diarizer.processSamples(audioChunk) {
|
| 56 |
+
for frame in 0..<result.frameCount {
|
| 57 |
+
for speaker in 0..<4 {
|
| 58 |
+
let prob = result.getSpeakerPrediction(speaker: speaker, frame: frame)
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Or batch processing
|
| 65 |
+
let timeline = try diarizer.processComplete(audioSamples)
|
| 66 |
+
for (speakerIndex, segments) in timeline.segments.enumerated() {
|
| 67 |
+
for segment in segments {
|
| 68 |
+
print("Speaker \(speakerIndex): \(segment.startTime)s - \(segment.endTime)s")
|
| 69 |
+
}
|
| 70 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
```
|
| 72 |
+
Performance
|
| 73 |
+
|
| 74 |
+
| Metric | Default | NVIDIA High |
|
| 75 |
+
|---------------|---------|-------------|
|
| 76 |
+
| Latency | ~1.12s | ~30.4s |
|
| 77 |
+
| RTFx (M4 Pro) | ~120x | ~118x |
|
| 78 |
|
| 79 |
+
Files
|
| 80 |
|
| 81 |
+
Models
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
- Sortformer.mlpackage / .mlmodelc - Default config (low latency)
|
| 84 |
+
- SortformerNvidiaLow.mlpackage / .mlmodelc - NVIDIA low latency config
|
| 85 |
+
- SortformerNvidiaHigh.mlpackage / .mlmodelc - NVIDIA high latency config
|
| 86 |
|
| 87 |
+
Scripts
|
| 88 |
|
| 89 |
+
- convert_to_coreml.py - PyTorch to CoreML conversion
|
| 90 |
+
- streaming_inference.py - Python streaming inference example
|
| 91 |
+
- mic_inference.py - Real-time microphone demo
|
| 92 |
|
| 93 |
+
Source
|
| 94 |
|
| 95 |
+
Original model: https://huggingface.co/nvidia/diar_streaming_sortformer_4spk-v2.1
|
| 96 |
|
| 97 |
+
Credits & Acknowledgements
|
| 98 |
|
| 99 |
+
This project would not have been possible without the significant technical contributions of https://huggingface.co/GradientDescent2718.
|
| 100 |
|
| 101 |
+
Their work was instrumental in:
|
| 102 |
|
| 103 |
+
- Architecture Conversion: Developing the complex PyTorch-to-CoreML conversion pipeline for the 17-layer Fast-Conformer and 18-layer Transformer heads.
|
| 104 |
+
- Build & Optimization: Engineering the static shape configurations that allow the model to achieve ~120x RTF on Apple Silicon.
|
| 105 |
+
- Logic Implementation: Porting the critical streaming state logic (speaker cache and FIFO management) to ensure consistent speaker identity tracking.
|
| 106 |
|
| 107 |
+
This project was built upon the foundational work of the NVIDIA NeMo team.
|
| 108 |
|
| 109 |
+
Key changes:
|
| 110 |
+
1. Describes all 3 model variants (Default, NVIDIA Low, NVIDIA High)
|
| 111 |
+
2. Updated model file names to match actual repo content
|
| 112 |
+
3. Fixed Swift API to match current `SortformerDiarizer` implementation
|
| 113 |
+
4. Updated performance numbers (RTFx ~120x based on your documentation)
|
| 114 |
+
5. Simplified input/output shapes table for combined model
|
| 115 |
+
6. Kept credits section intact
|