FluidInference/diar-streaming-sortformer-coreml
# Sortformer CoreML Models
Streaming speaker diarization models converted from NVIDIA's Sortformer to CoreML for Apple Silicon.
## Model Variants
The v2 and v2.1 refer to the version of the model weights to use. According to NVIDIA, v2.1 is more robust in meeting scenarios.
## Configuration Parameters
## Model Input/Output Shapes
General:
Note: C = chunk_len, L = chunk_left_context, R = chunk_right_context, S = spkcache_len, F = fifo_len.
Configuration-Specific Shapes:
## Usage with FluidAudio (Swift)
import FluidAudio
// Initialize with default config (auto-downloads from HuggingFace)
let diarizer = SortformerDiarizer(config: .default)
let models = try await SortformerModels.loadFromHuggingFace(config: .default)
diarizer.initialize(models: models)
// Streaming processing
for audioChunk in audioStream {
if let result = try diarizer.processSamples(audioChunk) {
for frame in 0..<result.frameCount {
for speaker in 0..<4 {
let prob = result.getSpeakerPrediction(speaker: speaker, frame: frame)
}
}
}
}
// Or batch processing
let timeline = try diarizer.processComplete(audioSamples)
for (speakerIndex, segments) in timeline.segments.enumerated() {
for segment in segments {
print("Speaker \(speakerIndex): \(segment.startTime)s - \(segment.endTime)s")
}
}Performance
https://github.com/FluidInference/FluidAudio/blob/main/Documentation/Benchmarks.md
Files
Models
- Sortformer.mlpackage / .mlmodelc - Default config (low latency)
- SortformerNvidiaLow.mlpackage / .mlmodelc - NVIDIA low latency config
- SortformerNvidiaHigh.mlpackage / .mlmodelc - NVIDIA high latency config
Scripts
- converttocoreml.py - PyTorch to CoreML conversion
- streaming_inference.py - Python streaming inference example
- mic_inference.py - Real-time microphone demo
Source
Original model: https://huggingface.co/nvidia/diarstreamingsortformer_4spk-v2.1
Credits & Acknowledgements
This project would not have been possible without the significant technical contributions of https://huggingface.co/GradientDescent2718.
Their work was instrumental in:
- Architecture Conversion: Developing the complex PyTorch-to-CoreML conversion pipeline for the 17-layer Fast-Conformer and 18-layer Transformer heads.
- Build & Optimization: Engineering the static shape configurations that allow the model to achieve ~120x RTF on Apple Silicon.
- Logic Implementation: Porting the critical streaming state logic (speaker cache and FIFO management) to ensure consistent speaker identity tracking.
This project was built upon the foundational work of the NVIDIA NeMo team.
