{"record":{"id":"0a32453a23517156","repo":"unslothai/unsloth","slug":"no-valid-audio-codes-found-after-start-of-speech-t","errorCode":null,"errorMessage":"No valid audio codes found after START_OF_SPEECH token","messagePattern":"No valid audio codes found after START_OF_SPEECH token","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/audio_codecs.py","lineNumber":163,"sourceCode":"        Returns (wav_bytes, 24000).\n        \"\"\"\n        # Find START_OF_SPEECH token (128257)\n        token_indices = (generated_ids == 128257).nonzero(as_tuple = True)\n        if len(token_indices[1]) > 0:\n            cropped = generated_ids[:, token_indices[1][-1] + 1 :]\n        else:\n            # Fall back to the entire output if the marker is missing\n            logger.warning(\"No START_OF_SPEECH token (128257) found — using full generated output\")\n            cropped = generated_ids\n        row = cropped[0]\n\n        # Remove EOS tokens (128258)\n        row = row[row != 128258]\n\n        # Trim to multiple of 7\n        row = row[: (len(row) // 7) * 7]\n        if len(row) == 0:\n            raise ValueError(\"No valid audio codes found after START_OF_SPEECH token\")\n\n        codes = [t.item() - 128266 for t in row]\n\n        # Redistribute into 3 SNAC layers (7 codes per frame → 1+2+4)\n        layer_1, layer_2, layer_3 = [], [], []\n        for i in range(len(codes) // 7):\n            layer_1.append(codes[7 * i])\n            layer_2.append(codes[7 * i + 1] - 4096)\n            layer_3.append(codes[7 * i + 2] - 8192)\n            layer_3.append(codes[7 * i + 3] - 12288)\n            layer_2.append(codes[7 * i + 4] - 16384)\n            layer_3.append(codes[7 * i + 5] - 20480)\n            layer_3.append(codes[7 * i + 6] - 24576)\n\n        snac_codes = [\n            torch.tensor(layer).unsqueeze(0).to(device) for layer in [layer_1, layer_2, layer_3]\n        ]\n","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/audio_codecs.py#L145-L181","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"def has_audio_frames(generated_ids, sos=128257, eos=128258) -> bool:\n    ids = generated_ids[0]\n    idx = (ids == sos).nonzero()\n    row = ids[idx[-1].item()+1:] if len(idx) else ids\n    row = row[row != eos]\n    return len(row) >= 7","typeGuard":null,"tryCatchPattern":"try:\n    wav, sr = decode_snac(generated_ids)\nexcept ValueError as e:\n    if \"No valid audio codes\" in str(e):\n        regenerate_with(seed=None, temperature=lower_temp)","preventionTips":["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"],"tags":["tts","audio","snac","orpheus","decode"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}