Whisper non_speech_tokens crashes with IndexError: encode(" -")[0] on empty result (0.4.4 STT)
Bug
In mlx-audio 0.4.4, the Whisper STT path crashes unconditionally with IndexError: list index out of range inside non_speech_tokens, blocking all transcription regardless of audio input.
Location
mlx_audio/stt/models/whisper/whisper.py:176 (in non_speech_tokens):
result = {self.encode(" -")[0], self.encode(" '")[0]}When the tokenizer's encode(" -") returns an empty list [], [0] raises IndexError. This fires during DecodingTask.__init__ → get_suppress_tokens for every transcription call, so no audio can ever be transcribed.
Reproduce
Minimal (no server):
from mlx_audio.stt.utils import load_model
m = load_model("mlx-community/whisper-tiny.en-mlx-q4")
m.generate("audio.wav", language="en")
# -> IndexError: list index out of range (whisper.py:176)Traceback
File ".../mlx_audio/stt/models/whisper/whisper.py", line 176, in non_speech_tokens
result = {self.encode(" -")[0], self.encode(" '")[0]}
IndexError: list index out of rangeEnvironment
- mlx-audio: 0.4.4 (pip-installed)
- Python 3.12 / 3.14, Apple Silicon (M-series)
- Model:
mlx-community/whisper-tiny.en-mlx-q4(weights load fine — crash is in the decode/suppress-token init, not model load)
Suspected cause
The bare [0] indexing assumes encode(" -") and encode(" '") always return a non-empty list. For the whisper-tiny.en tokenizer (and possibly others) these return [] — likely because - / ' are not in the English-only subword vocab as standalone tokens. 0.4.3 did not crash; this looks like a regression introduced in 0.4.4 (the surrounding symbols/miscellaneous loop already guards len(tokens) == 1, but the seeding line 176 does not).
Suggested fix
Guard the two seeding encodes the same way the loop below already guards its encodes:
result = set()
for seed in (" -", " '"):
toks = self.encode(seed)
if toks:
result.add(toks[0])This keeps the original intent (seed with the space-prefixed dash/quote tokens when they exist) while not crashing when they don't.
Impact
Downstream server (fusion-mlx, tracking as dahai80/fusion-mlx#668) pins mlx-audio==0.4.3, but the pin drifted to 0.4.4 and STT is fully blocked. A guard here would let 0.4.4+ work for English-only Whisper models.
Happy to open a PR if this approach looks right. Thanks for the great library!
Source: Blaizzy/mlx-audio