Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

Remove auto support for whisper_device; only cpu and cuda allowed

Cursor Agentdb646ef2dbc1
diff --git a/.env.example b/.env.example
index 4f763fa3..022f08a7 100644
--- a/.env.example
+++ b/.env.example
@@ -38,7 +38,7 @@ WHISPER_MODEL=base
HF_TOKEN=""
-# WHISPER_DEVICE: "cpu" | "cuda" | "auto" (auto = try CUDA, fail fast; no fallback)
+# WHISPER_DEVICE: "cpu" | "cuda"
WHISPER_DEVICE=cpu
diff --git a/README.md b/README.md
index 6b7b702a..4bc189d7 100644
--- a/README.md
+++ b/README.md
@@ -249,7 +249,7 @@ uv sync --extra voice
|----------|-------------|---------|
| `VOICE_NOTE_ENABLED` | Enable voice note handling | `true` |
| `WHISPER_MODEL` | Model size: `tiny`, `base`, `small`, `medium`, `large-v2`, `large-v3`, `large-v3-turbo` | `base` |
-| `WHISPER_DEVICE` | `cpu` \| `cuda` \| `auto` (auto = try CUDA, fail fast; no fallback) | `cpu` |
+| `WHISPER_DEVICE` | `cpu` \| `cuda` | `cpu` |
| `HF_TOKEN` | Hugging Face token for faster model downloads (optional; [create one](https://huggingface.co/settings/tokens)) | — |
---
@@ -335,7 +335,7 @@ Browse: [model.lmstudio.ai](https://model.lmstudio.ai)
| `ALLOWED_TELEGRAM_USER_ID` | Allowed Telegram User ID | `""` |
| `VOICE_NOTE_ENABLED` | Enable voice note handling | `true` |
| `WHISPER_MODEL` | Local Whisper model size | `base` |
-| `WHISPER_DEVICE` | `cpu` \| `cuda` \| `auto` (fail fast; no fallback) | `cpu` |
+| `WHISPER_DEVICE` | `cpu` \| `cuda` | `cpu` |
| `MESSAGING_RATE_LIMIT` | Messaging messages per window | `1` |
| `MESSAGING_RATE_WINDOW` | Messaging window (seconds) | `1` |
| `CLAUDE_WORKSPACE` | Directory for agent workspace | `./agent_workspace` |
diff --git a/config/settings.py b/config/settings.py
index e548cc83..cd92f4c5 100644
--- a/config/settings.py
+++ b/config/settings.py
@@ -80,7 +80,7 @@ class Settings(BaseSettings):
hf_token: str = Field(default="", validation_alias="HF_TOKEN")
# Model size: "tiny" | "base" | "small" | "medium" | "large-v2" | "large-v3" | "large-v3-turbo"
whisper_model: str = Field(default="base", validation_alias="WHISPER_MODEL")
- # Device: "cpu" | "cuda" | "auto" (auto = try cuda, fail fast; no fallback)
+ # Device: "cpu" | "cuda"
whisper_device: str = Field(default="cpu", validation_alias="WHISPER_DEVICE")
# ==================== Bot Wrapper Config ====================
@@ -115,6 +115,13 @@ class Settings(BaseSettings):
return None
return v
+ @field_validator("whisper_device")
+ @classmethod
+ def validate_whisper_device(cls, v: str) -> str:
+ if v not in ("cpu", "cuda"):
+ raise ValueError(f"whisper_device must be 'cpu' or 'cuda', got {v!r}")
+ return v
+
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
diff --git a/messaging/transcription.py b/messaging/transcription.py
index 8a62c37e..3e21f082 100644
--- a/messaging/transcription.py
+++ b/messaging/transcription.py
@@ -26,8 +26,9 @@ class _WhisperModelLike(Protocol):
def _get_local_model(whisper_model: str, device: str) -> _WhisperModelLike:
"""Lazy-load faster-whisper model. Raises ImportError if not installed."""
global _model_cache
- resolved = device if device in ("cpu", "cuda") else "auto"
- cache_key = (whisper_model, resolved)
+ if device not in ("cpu", "cuda"):
+ raise ValueError(f"whisper_device must be 'cpu' or 'cuda', got {device!r}")
+ cache_key = (whisper_model, device)
if cache_key not in _model_cache:
try:
from config.settings import get_settings
@@ -39,15 +40,12 @@ def _get_local_model(whisper_model: str, device: str) -> _WhisperModelLike:
faster_whisper = importlib.import_module("faster_whisper")
WhisperModel = faster_whisper.WhisperModel
- if resolved == "auto":
- # Try CUDA; fail fast if CUDA unavailable (no CPU fallback)
- _model_cache[cache_key] = WhisperModel(whisper_model, device="cuda")
- elif resolved == "cpu":
+ if device == "cpu":
_model_cache[cache_key] = WhisperModel(
whisper_model, device="cpu", compute_type="float32"
)
else:
- _model_cache[cache_key] = WhisperModel(whisper_model, device=resolved)
+ _model_cache[cache_key] = WhisperModel(whisper_model, device=device)
except ImportError as e:
raise ImportError(
"Voice notes require the voice extra. Install with: uv sync --extra voice"
@@ -69,7 +67,7 @@ def transcribe_audio(
file_path: Path to audio file (OGG, MP3, MP4, WAV, M4A supported)
mime_type: MIME type of the audio (e.g. "audio/ogg")
whisper_model: Model size: "tiny", "base", "small", "medium", "large-v2", "large-v3", "large-v3-turbo"
- whisper_device: "cpu" | "cuda" | "auto" (auto = try CUDA, fail fast; no fallback)
+ whisper_device: "cpu" | "cuda"
Returns:
Transcribed text
diff --git a/tests/config/test_config.py b/tests/config/test_config.py
index 269ab724..758d4dd5 100644
--- a/tests/config/test_config.py
+++ b/tests/config/test_config.py
@@ -303,3 +303,20 @@ class TestSettingsOptionalStr:
monkeypatch.setenv("MESSAGING_PLATFORM", "discord")
s = Settings()
assert s.messaging_platform == "discord"
+
+ def test_whisper_device_auto_rejected(self, monkeypatch):
+ """WHISPER_DEVICE=auto raises ValidationError (auto removed)."""
+ from config.settings import Settings
+
+ monkeypatch.setenv("WHISPER_DEVICE", "auto")
+ with pytest.raises(ValidationError, match="whisper_device"):
+ Settings()
+
+ @pytest.mark.parametrize("device", ["cpu", "cuda"])
+ def test_whisper_device_valid(self, monkeypatch, device):
+ """Valid whisper_device values are accepted."""
+ from config.settings import Settings
+
+ monkeypatch.setenv("WHISPER_DEVICE", device)
+ s = Settings()
+ assert s.whisper_device == device
diff --git a/tests/messaging/test_transcription.py b/tests/messaging/test_transcription.py
index e58237fd..2cb4624b 100644
--- a/tests/messaging/test_transcription.py
+++ b/tests/messaging/test_transcription.py
@@ -73,6 +73,18 @@ def test_transcribe_local_empty_segments_returns_no_speech():
path.unlink(missing_ok=True)
+def test_transcribe_invalid_device_raises():
+ """Invalid whisper_device raises ValueError."""
+ with tempfile.NamedTemporaryFile(suffix=".ogg", delete=False) as f:
+ f.write(b"fake ogg")
+ path = Path(f.name)
+ try:
+ with pytest.raises(ValueError, match="whisper_device must be 'cpu' or 'cuda'"):
+ transcribe_audio(path, "audio/ogg", whisper_device="auto")
+ finally:
+ path.unlink(missing_ok=True)
+
+
def test_transcribe_local_import_error_raises():
"""Local backend when faster-whisper not installed raises ImportError."""
with tempfile.NamedTemporaryFile(suffix=".ogg", delete=False) as f: