mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-14 10:52:21 +02:00
Squash Odysseus development history
This commit is contained in:
+28
-11
@@ -40,6 +40,8 @@ class STTService:
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
settings = self._load_settings()
|
||||
if settings.get("stt_enabled") is False:
|
||||
return False
|
||||
provider = settings["stt_provider"]
|
||||
if provider == "disabled":
|
||||
return False
|
||||
@@ -57,17 +59,29 @@ class STTService:
|
||||
if self._whisper_model is None:
|
||||
try:
|
||||
from faster_whisper import WhisperModel
|
||||
settings = self._load_settings()
|
||||
model_size = settings.get("stt_model", "base")
|
||||
# Use CPU by default; will use CUDA if available
|
||||
import torch
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
compute_type = "float16" if device == "cuda" else "int8"
|
||||
self._whisper_model = WhisperModel(model_size, device=device, compute_type=compute_type)
|
||||
logger.info(f"faster-whisper model '{model_size}' loaded on {device}")
|
||||
except ImportError:
|
||||
logger.warning("faster-whisper not installed. Install with: pip install faster-whisper")
|
||||
return None
|
||||
try:
|
||||
settings = self._load_settings()
|
||||
model_size = settings.get("stt_model", "base")
|
||||
# faster-whisper runs on CTranslate2, not torch. torch is only
|
||||
# used (optionally) to detect a CUDA device for acceleration —
|
||||
# if it's missing or unusable we just run on CPU. Keeping this
|
||||
# probe separate (and tolerant of any failure, e.g. a broken
|
||||
# CUDA/torch install that raises OSError on import) means a
|
||||
# torch-less or torch-broken machine still does CPU
|
||||
# transcription instead of failing with a misleading
|
||||
# "faster-whisper not installed" error.
|
||||
try:
|
||||
import torch
|
||||
use_cuda = torch.cuda.is_available()
|
||||
except Exception:
|
||||
use_cuda = False
|
||||
device = "cuda" if use_cuda else "cpu"
|
||||
compute_type = "float16" if device == "cuda" else "int8"
|
||||
self._whisper_model = WhisperModel(model_size, device=device, compute_type=compute_type)
|
||||
logger.info(f"faster-whisper model '{model_size}' loaded on {device}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load whisper model: {e}")
|
||||
return None
|
||||
@@ -77,6 +91,7 @@ class STTService:
|
||||
model = self._get_whisper()
|
||||
if not model:
|
||||
return None
|
||||
tmp_path = None
|
||||
try:
|
||||
# Write to temp file (faster-whisper needs a file path or file-like)
|
||||
with tempfile.NamedTemporaryFile(suffix=".webm", delete=False) as tmp:
|
||||
@@ -90,14 +105,14 @@ class STTService:
|
||||
segments, info = model.transcribe(tmp_path, **kwargs)
|
||||
text = " ".join(seg.text.strip() for seg in segments)
|
||||
|
||||
# Cleanup
|
||||
Path(tmp_path).unlink(missing_ok=True)
|
||||
|
||||
logger.info(f"Local STT: {len(text)} chars, lang={info.language}, prob={info.language_probability:.2f}")
|
||||
return text
|
||||
except Exception as e:
|
||||
logger.error(f"Local STT transcription failed: {e}", exc_info=True)
|
||||
return None
|
||||
finally:
|
||||
if tmp_path:
|
||||
Path(tmp_path).unlink(missing_ok=True)
|
||||
|
||||
# ── API endpoint ──
|
||||
|
||||
@@ -140,6 +155,8 @@ class STTService:
|
||||
|
||||
def transcribe(self, audio_bytes: bytes) -> Optional[str]:
|
||||
settings = self._load_settings()
|
||||
if settings.get("stt_enabled") is False:
|
||||
return None
|
||||
provider = settings["stt_provider"]
|
||||
model = settings["stt_model"]
|
||||
language = settings.get("stt_language", "")
|
||||
|
||||
Reference in New Issue
Block a user