Skip to content

Open-source alternative to Opus Clip, Vidyo.ai, Klap & SubMagic. Turn long-form YouTube videos into viral 9:16 shorts using LLM highlight detection, Whisper transcription, and auto vertical cropping — free, no watermarks, no per-clip credits.

fix: swap openai-whisper for faster-whisper to avoid SHA256 download loop

Anil Matcha3cd7ce7d8bba
diff --git a/requirements.txt b/requirements.txt
index 1c3c7e9..edb59eb 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
requests>=2.31
python-dotenv>=1.0
-openai-whisper>=20231117
+faster-whisper>=1.0.0
diff --git a/shorts_generator/transcriber.py b/shorts_generator/transcriber.py
index dcb98fb..7538eb3 100644
--- a/shorts_generator/transcriber.py
+++ b/shorts_generator/transcriber.py
@@ -1,8 +1,11 @@
"""Local Whisper transcription.
Takes the hosted mp4 URL returned by MuAPI's /youtube-download, streams it to
-disk, runs OpenAI's open-source Whisper model locally, and emits the segment
-shape expected by the highlight generator: {duration, segments[start,end,text]}.
+disk, runs faster-whisper locally, and emits the segment shape expected by the
+highlight generator: {duration, segments[start,end,text]}.
+
+Uses faster-whisper instead of openai-whisper: resumable HF downloads, no
+SHA256 self-validation loop on a partial file, and faster CPU inference.
"""
import os
import shutil
@@ -13,19 +16,20 @@ import requests
_WHISPER_MODEL = None
+_WHISPER_MODEL_SIZE = None
def _load_model(model_size: str):
- """Lazy-load whisper. Cached across calls so we only pay model-load cost once."""
- global _WHISPER_MODEL
- if _WHISPER_MODEL is not None:
+ """Lazy-load faster-whisper. Cached across calls so we only pay model-load cost once."""
+ global _WHISPER_MODEL, _WHISPER_MODEL_SIZE
+ if _WHISPER_MODEL is not None and _WHISPER_MODEL_SIZE == model_size:
return _WHISPER_MODEL
try:
- import whisper
+ from faster_whisper import WhisperModel
except ImportError as e:
raise RuntimeError(
- "openai-whisper is not installed. Run: pip install -U openai-whisper\n"
+ "faster-whisper is not installed. Run: pip install -U faster-whisper\n"
"It also needs ffmpeg available on PATH."
) from e
@@ -36,8 +40,17 @@ def _load_model(model_size: str):
" Ubuntu: sudo apt install ffmpeg"
)
- print(f"[transcribe] loading whisper model '{model_size}' (first run downloads weights)", flush=True)
- _WHISPER_MODEL = whisper.load_model(model_size)
+ cache_dir = os.path.join(os.path.expanduser("~"), ".cache", "faster-whisper")
+ os.makedirs(cache_dir, exist_ok=True)
+
+ print(f"[transcribe] loading faster-whisper model '{model_size}' (first run downloads weights)", flush=True)
+ _WHISPER_MODEL = WhisperModel(
+ model_size,
+ device="cpu",
+ compute_type="int8",
+ download_root=cache_dir,
+ )
+ _WHISPER_MODEL_SIZE = model_size
return _WHISPER_MODEL
@@ -56,33 +69,33 @@ def _download_to_temp(media_url: str) -> str:
def transcribe(media_url: str, model_size: str = "base", language: Optional[str] = None) -> Dict:
- """Run local Whisper on a hosted media URL. Returns {duration, segments[...]}.
+ """Run local faster-whisper on a hosted media URL. Returns {duration, segments[...]}.
- model_size: tiny | base | small | medium | large — bigger = more accurate, slower.
+ model_size: tiny | base | small | medium | large-v3 — bigger = more accurate, slower.
"""
model = _load_model(model_size)
local_path = _download_to_temp(media_url)
try:
print(f"[transcribe] running whisper on {local_path}", flush=True)
- result = model.transcribe(
+ segments_iter, info = model.transcribe(
local_path,
language=language,
- verbose=False,
+ beam_size=5,
+ vad_filter=True,
)
+ segments = []
+ for s in segments_iter:
+ segments.append({
+ "start": float(s.start),
+ "end": float(s.end),
+ "text": (s.text or "").strip(),
+ })
finally:
try:
os.remove(local_path)
except OSError:
pass
- segments = []
- for s in result.get("segments", []):
- segments.append({
- "start": float(s["start"]),
- "end": float(s["end"]),
- "text": (s.get("text") or "").strip(),
- })
-
- duration = segments[-1]["end"] if segments else 0.0
+ duration = float(getattr(info, "duration", 0.0)) or (segments[-1]["end"] if segments else 0.0)
print(f"[transcribe] {len(segments)} segments, {duration:.0f}s of audio", flush=True)
return {"duration": duration, "segments": segments}