This is a pinned, validated MLX export of
speechbrain/lang-id-voxlingua107-ecapa
for native Apple Silicon inference. It ranks 107 spoken-language labels.
The runtime contract includes sentence-level mean normalization. The exporter
compares an independent periodic-Hamming, symmetric-filter frontend with the
official SpeechBrain implementation before accepting the weights.
The upstream card reports 6.7% error on a small 33-language development
subset, not a complete test over all 107 labels. Product evaluation should use
the intended languages, accents, microphones, noise, and short-utterance mix.
1import json
2import mlx.core as mx
3import soundfile as sf
4
5from frontend import compute_fbank
6from mlx_model import LanguageIDModel
7
8audio, sample_rate = sf.read("recording.wav", dtype="float32")
9assert sample_rate == 16000 and audio.ndim == 1
10features = compute_fbank(audio, 60)[None, :, :]
11model = LanguageIDModel()
12model.load_weights(list(mx.load("model.safetensors").items()), strict=True)
13log_probabilities = model(mx.array(features))
14mx.eval(log_probabilities)
15labels = json.load(open("labels.json", encoding="utf-8"))
16best = int(mx.argmax(log_probabilities, axis=-1).item())
17print(labels[best], float(mx.exp(log_probabilities[0, best]).item()))
This is a closed-set classifier and is not an unknown-language detector. Keep
the original class indexes; normalized aliases belong in application output,
not in the model head.