Commit 11a0fd46 authored by Your Name's avatar Your Name

Fix: Fall back to whispercpp when faster-whisper fails to load

- Add faster_whisper_failed flag to properly track failures
- When faster-whisper throws non-ImportError (e.g., GGUF not supported),
  now falls back to whispercpp instead of failing
- Applies to both pre-loading and transcription endpoint
parent fee8a9dd
...@@ -2383,7 +2383,8 @@ async def create_transcription( ...@@ -2383,7 +2383,8 @@ async def create_transcription(
tmp_path = tmp.name tmp_path = tmp.name
try: try:
# Try faster-whisper first (requires PyTorch) # Try faster-whisper first (requires PyTorch), fall back to whispercpp if it fails
faster_whisper_failed = False
try: try:
from faster_whisper import WhisperModel from faster_whisper import WhisperModel
...@@ -2479,7 +2480,15 @@ async def create_transcription( ...@@ -2479,7 +2480,15 @@ async def create_transcription(
return {"text": full_text} return {"text": full_text}
except ImportError: except ImportError:
# faster-whisper not available, try whispercpp (no PyTorch required) # faster-whisper not available, will try whispercpp below
faster_whisper_failed = True
except Exception as e:
# faster-whisper failed for some other reason (e.g., GGUF file not supported)
print(f"Warning: faster-whisper failed to load model: {e}")
faster_whisper_failed = True
# If faster-whisper failed (not installed or couldn't load), try whispercpp
if faster_whisper_failed:
try: try:
import whispercpp import whispercpp
...@@ -3746,6 +3755,8 @@ def main(): ...@@ -3746,6 +3755,8 @@ def main():
should_preload = load_mode in ("loadall", "loadswap") or (model_name is None and args.audio_model) should_preload = load_mode in ("loadall", "loadswap") or (model_name is None and args.audio_model)
if should_preload: if should_preload:
print(f"Pre-loading audio model...") print(f"Pre-loading audio model...")
# First try faster-whisper, then fall back to whispercpp if it fails
faster_whisper_failed = False
try: try:
# Try faster-whisper first (requires torch) # Try faster-whisper first (requires torch)
from faster_whisper import WhisperModel from faster_whisper import WhisperModel
...@@ -3782,7 +3793,15 @@ def main(): ...@@ -3782,7 +3793,15 @@ def main():
print(f"Audio model loaded successfully (faster-whisper)") print(f"Audio model loaded successfully (faster-whisper)")
except ImportError: except ImportError:
# faster-whisper not available, try whispercpp (no torch required) # faster-whisper not available, will try whispercpp below
faster_whisper_failed = True
except Exception as e:
# faster-whisper failed for some other reason (e.g., GGUF file not supported)
print(f"Warning: faster-whisper failed to load model: {e}")
faster_whisper_failed = True
# If faster-whisper failed (not installed or couldn't load), try whispercpp
if faster_whisper_failed:
try: try:
import whispercpp import whispercpp
...@@ -3854,10 +3873,6 @@ def main(): ...@@ -3854,10 +3873,6 @@ def main():
except Exception as e: except Exception as e:
print(f"Warning: Could not pre-load audio model with whispercpp: {e}") print(f"Warning: Could not pre-load audio model with whispercpp: {e}")
print("Audio model will load on-demand when transcription is requested.") print("Audio model will load on-demand when transcription is requested.")
except Exception as e:
print(f"Warning: Could not pre-load audio model: {e}")
print("Audio model will load on-demand when transcription is requested.")
# Set up TTS model if specified # Set up TTS model if specified
if args.tts_model: if args.tts_model:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment