{"record":{"id":"06424fdf08badca3","repo":"unslothai/unsloth","slug":"could-not-decode-the-audio-06424f","errorCode":null,"errorMessage":"Could not decode the audio.","messagePattern":"Could not decode the audio\\.","errorType":"http","errorClass":"SttAudioDecodeError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/stt_sidecar.py","lineNumber":1106,"sourceCode":"    )\n    # Group frames before resampling so short clips need one resampler call\n    # rather than one per codec frame.\n    fifo = av.audio.fifo.AudioFifo()\n\n    def write_frame(frame) -> None:\n        nonlocal sample_count\n        array = frame.to_ndarray()\n        sample_count += array.size\n        if sample_count > max_samples:\n            max_minutes = _MAX_AUDIO_SECONDS // 60\n            unit = \"minute\" if max_minutes == 1 else \"minutes\"\n            raise SttAudioTooLongError(f\"Audio must be {max_minutes} {unit} or shorter.\")\n        raw_buffer.write(array)\n\n    try:\n        with av.open(io.BytesIO(audio), mode = \"r\", metadata_errors = \"ignore\") as container:\n            if not container.streams.audio:\n                raise SttAudioDecodeError(\"Could not decode the audio.\")\n            frames = iter(container.decode(audio = 0))\n            while True:\n                try:\n                    frame = next(frames)\n                except StopIteration:\n                    break\n                except InvalidDataError:\n                    # Skip a corrupt frame rather than fail the whole transcription.\n                    continue\n                if cancel_event is not None and cancel_event.is_set():\n                    raise SttTranscriptionCancelledError(\"Transcription cancelled.\")\n                frame.pts = None\n                fifo.write(frame)\n                if fifo.samples >= 500000:\n                    for resampled in resampler.resample(fifo.read()):\n                        write_frame(resampled)\n            if fifo.samples > 0:\n                for resampled in resampler.resample(fifo.read()):","sourceCodeStart":1088,"sourceCodeEnd":1124,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/stt_sidecar.py#L1088-L1124","documentation":"Raised inside the PyAV decode loop when the opened container exposes no audio stream (container.streams.audio is empty). The bytes opened fine as a media container, but there is no audio track to transcribe — e.g. a video-only file or an empty/misidentified file.","triggerScenarios":"Calling transcribe() with a video file that has no audio track, a zero-byte or truncated file that PyAV still opens, or a container whose streams are all video/data.","commonSituations":"Drag-and-drop upload accepting video files; a recorder producing an empty webm when permission was denied; a file with the wrong extension that FFmpeg probes as a non-audio container.","solutions":["Inspect the file client-side (ffprobe or the browser's audio element) and reject non-audio inputs before upload.","Check the file size is non-zero and the MIME type is an audio type before calling transcribe.","If you expect audio from a recorder, verify the recorder actually produced samples (e.g. MediaRecorder ondataavailable events had data)."],"exampleFix":"// before\nstt.transcribe(file_bytes);  // video-only mp4 -> SttAudioDecodeError\n// after\nif not has_audio_stream(file_bytes):  # ffprobe-style probe\n    return error(\"File has no audio track\")\nstt.transcribe(file_bytes)","handlingStrategy":"validation","validationCode":"import av, io\nwith av.open(io.BytesIO(audio), mode=\"r\", metadata_errors=\"ignore\") as c:\n    if not c.streams.audio:\n        reject(\"no audio track\")","typeGuard":null,"tryCatchPattern":"try:\n    stt.transcribe(audio)\nexcept SttAudioDecodeError as e:\n    if \"no audio\" in context: reject_upload()  # distinguish via upstream probe\n    else: raise","preventionTips":["Accept only audio/* MIME types in upload forms","Probe files with ffprobe/av.open before sending to the API","Reject zero-byte uploads before they reach transcription"],"tags":["stt","audio","decode","container","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}