unslothai/unsloth · error · ValueError
No valid audio codes found after START_OF_SPEECH token
Error message
No valid audio codes found after START_OF_SPEECH token
What it means
Raised while decoding Orpheus-style SNAC audio codes: after cropping generated token ids at the START_OF_SPEECH token (128257), stripping EOS (128258) and truncating to a multiple of 7, the remaining row is empty. The model produced no audio frames — only markers/EOS or an immediate end after speech start.
Source
Thrown at studio/backend/core/inference/audio_codecs.py:163
Returns (wav_bytes, 24000).
"""
# Find START_OF_SPEECH token (128257)
token_indices = (generated_ids == 128257).nonzero(as_tuple = True)
if len(token_indices[1]) > 0:
cropped = generated_ids[:, token_indices[1][-1] + 1 :]
else:
# Fall back to the entire output if the marker is missing
logger.warning("No START_OF_SPEECH token (128257) found — using full generated output")
cropped = generated_ids
row = cropped[0]
# Remove EOS tokens (128258)
row = row[row != 128258]
# Trim to multiple of 7
row = row[: (len(row) // 7) * 7]
if len(row) == 0:
raise ValueError("No valid audio codes found after START_OF_SPEECH token")
codes = [t.item() - 128266 for t in row]
# Redistribute into 3 SNAC layers (7 codes per frame → 1+2+4)
layer_1, layer_2, layer_3 = [], [], []
for i in range(len(codes) // 7):
layer_1.append(codes[7 * i])
layer_2.append(codes[7 * i + 1] - 4096)
layer_3.append(codes[7 * i + 2] - 8192)
layer_3.append(codes[7 * i + 3] - 12288)
layer_2.append(codes[7 * i + 4] - 16384)
layer_3.append(codes[7 * i + 5] - 20480)
layer_3.append(codes[7 * i + 6] - 24576)
snac_codes = [
torch.tensor(layer).unsqueeze(0).to(device) for layer in [layer_1, layer_2, layer_3]
]
View on GitHub (pinned to 203007d190)
Solutions
- Retry generation with different sampling (lower temperature, adjust repetition penalty) — degenerate continuations are often stochastic
- Increase max_new_tokens so at least one 7-code frame can be produced
- Verify non-empty input text and a valid speaker/voice reference
- If it consistently fails, the checkpoint or tokenizer mapping is wrong for the audio head — reload the correct TTS model files
Defensive patterns
Strategy: fallback
Validate before calling
def has_audio_frames(generated_ids, sos=128257, eos=128258) -> bool:
ids = generated_ids[0]
idx = (ids == sos).nonzero()
row = ids[idx[-1].item()+1:] if len(idx) else ids
row = row[row != eos]
return len(row) >= 7 Try / catch
try:
wav, sr = decode_snac(generated_ids)
except ValueError as e:
if "No valid audio codes" in str(e):
regenerate_with(seed=None, temperature=lower_temp) Prevention
- Set max_new_tokens generously for TTS turns
- Validate non-empty input text before TTS
- Use known-good speaker/voice references for the Orpheus model
When it happens
Trigger: The TTS model generates EOS immediately after START_OF_SPEECH (silent/degenerate continuation); audio-token head misconfigured so no valid code ids in range appear; generation parameters (temperature, repetition penalty, max tokens) truncate output before any 7-code frame; a fallback path used the whole output when the SOS marker was absent and it contained no usable codes.
Common situations: Wrong or mismatched voice/prompt tokens for the Orpheus model; max_new_tokens set too low; quantized/GGUF TTS model dropping audio tokens; empty or whitespace input text.
Related errors
- No bicodec_semantic tokens found in generated output
- No DAC code tokens (c1/c2) found in generated output
- Model {self.active_model_name} is not an audio model
- Audio generation cancelled
- Unknown audio_type: {audio_type}
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/0a32453a23517156.
Report an issue: GitHub.