{"record":{"id":"60300c1bb469487a","repo":"unslothai/unsloth","slug":"speech-to-text-needs-pytorch-transformers-and-py","errorCode":null,"errorMessage":"Speech-to-text needs PyTorch, Transformers, and PyAV. Run `unsloth studio update` to install them.","messagePattern":"Speech-to-text needs PyTorch, Transformers, and PyAV\\. Run `unsloth studio update` to install them\\.","errorType":"http","errorClass":"SttUnavailableError","httpStatus":501,"severity":"error","filePath":"studio/backend/core/inference/stt_sidecar.py","lineNumber":285,"sourceCode":"\ndef _known_whisper_languages() -> Optional[frozenset[str]]:\n    \"\"\"Return Whisper's language codes without constructing/loading a model.\"\"\"\n    try:\n        from transformers.models.whisper.tokenization_whisper import LANGUAGES\n    except Exception:\n        # Transformers unavailable or the constant moved: skip the check.\n        return None\n    return frozenset(LANGUAGES)\n\n\ndef ensure_stt_available() -> None:\n    \"\"\"Raise when the complete local Whisper backend cannot be imported.\"\"\"\n    try:\n        import av  # noqa: F401\n        import torch  # noqa: F401\n        import transformers  # noqa: F401\n    except Exception as exc:\n        raise SttUnavailableError(\n            \"Speech-to-text needs PyTorch, Transformers, and PyAV. \"\n            \"Run `unsloth studio update` to install them.\"\n        ) from exc\n\n\ndef is_available() -> bool:\n    \"\"\"True when the complete local Whisper backend can be imported.\"\"\"\n    try:\n        ensure_stt_available()\n    except SttUnavailableError:\n        return False\n    return True\n\n\ndef resolve_model_id(model: Optional[str]) -> str:\n    \"\"\"Resolve a curated id or validate a custom Hugging Face repository.\"\"\"\n    if not model:\n        return DEFAULT_STT_MODEL","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/stt_sidecar.py#L267-L303","documentation":"SttUnavailableError raised by ensure_stt_available() when importing av, torch, or transformers fails. It marks the Transformers Whisper backend as not installed and tells the user to run `unsloth studio update`; is_available() wraps it to probe capability without raising.","triggerScenarios":"Any call into the Transformers STT backend (ensure_stt_available, model download, transcription) on an environment where PyTorch, Transformers, or PyAV is missing, broken (e.g. CUDA DLL mismatch), or not importable.","commonSituations":"Partial install or interrupted `unsloth studio update`; a Python upgrade breaking compiled wheels; a venv missing optional extras; importing studio backend outside its bundled environment.","solutions":["Run `unsloth studio update` to install/repair the three packages.","Verify the environment: `python -c \"import torch, transformers, av\"` and read the underlying ImportError chain (the original exception is attached via `from exc`).","If a specific import fails (e.g. torch/CUDA), fix that dependency version in the studio environment.","Gate features on is_available() so the UI degrades gracefully instead of hitting the raise."],"exampleFix":"```python\n# before\nresult = stt_sidecar.transcribe(audio_bytes)\n\n# after\nfrom studio.backend.core.inference import stt_sidecar\n\nif not stt_sidecar.is_available():\n    show_message(\"Run `unsloth studio update` to enable local speech-to-text.\")\nelse:\n    result = stt_sidecar.transcribe(audio_bytes)\n```","handlingStrategy":"type-guard","validationCode":"```python\nimport importlib.util\nmissing = [m for m in (\"torch\", \"transformers\", \"av\") if importlib.util.find_spec(m) is None]\nif missing:\n    show_setup_prompt(missing)  # suggest `unsloth studio update`\n```","typeGuard":"```python\ndef stt_backend_available() -> bool:\n    \"\"\"True when the local Whisper backend can run.\"\"\"\n    return stt_sidecar.is_available()\n```","tryCatchPattern":"```python\ntry:\n    stt_sidecar.ensure_stt_available()\nexcept SttUnavailableError as exc:\n    show_error(\"Run `unsloth studio update` to install speech-to-text deps.\", cause=exc.__cause__)\n```","preventionTips":["Gate the Voice UI on is_available() at startup.","Run `unsloth studio update` after any Python or studio upgrade.","Inspect exc.__cause__ to see which of torch/transformers/av failed to import."],"tags":["stt","dependencies","environment","import-error"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}