|
| 1 | +PYTHON := python3 |
| 2 | +VENV := .venv |
| 3 | +PIP := $(VENV)/bin/pip |
| 4 | +PY := $(VENV)/bin/python |
| 5 | + |
| 6 | +# ── Default config/output ───────────────────────────────────────────────────── |
| 7 | +CONFIG ?= config.json |
| 8 | +BACKEND ?= faster_whisper |
| 9 | +LANGUAGE ?= fr |
| 10 | +WORKERS ?= 2 |
| 11 | +OUTPUT ?= ./output |
| 12 | +FILE ?= |
| 13 | +URL ?= |
| 14 | + |
| 15 | +.DEFAULT_GOAL := help |
| 16 | + |
| 17 | +# ── Setup ───────────────────────────────────────────────────────────────────── |
| 18 | + |
| 19 | +.PHONY: install |
| 20 | +install: ## Full installation (venv + deps + config) |
| 21 | + bash install.sh |
| 22 | + |
| 23 | +.PHONY: venv |
| 24 | +venv: ## Create virtual environment only |
| 25 | + $(PYTHON) -m venv $(VENV) |
| 26 | + $(PIP) install --upgrade pip --quiet |
| 27 | + |
| 28 | +.PHONY: deps |
| 29 | +deps: venv ## Install core dependencies |
| 30 | + $(PIP) install --quiet ffmpeg-python tqdm requests yt-dlp pydub |
| 31 | + |
| 32 | +.PHONY: deps-faster-whisper |
| 33 | +deps-faster-whisper: deps ## Install faster-whisper backend |
| 34 | + $(PIP) install --quiet faster-whisper |
| 35 | + |
| 36 | +.PHONY: deps-openai |
| 37 | +deps-openai: deps ## Install OpenAI backend |
| 38 | + $(PIP) install --quiet openai |
| 39 | + |
| 40 | +.PHONY: deps-all |
| 41 | +deps-all: deps deps-faster-whisper deps-openai ## Install all Python dependencies |
| 42 | + |
| 43 | +# ── whisper.cpp ─────────────────────────────────────────────────────────────── |
| 44 | + |
| 45 | +WHISPER_CPP_DIR := whisper.cpp |
| 46 | +WHISPER_MODEL ?= base |
| 47 | +WHISPER_MODEL_BIN := $(WHISPER_CPP_DIR)/models/ggml-$(WHISPER_MODEL).bin |
| 48 | + |
| 49 | +.PHONY: whisper-cpp-build |
| 50 | +whisper-cpp-build: ## Clone and compile whisper.cpp |
| 51 | + @if [ ! -d "$(WHISPER_CPP_DIR)" ]; then \ |
| 52 | + echo "[+] Cloning whisper.cpp..."; \ |
| 53 | + git clone --depth=1 https://github.com/ggerganov/whisper.cpp $(WHISPER_CPP_DIR); \ |
| 54 | + else \ |
| 55 | + echo "[+] whisper.cpp already cloned."; \ |
| 56 | + fi |
| 57 | + @echo "[+] Compiling..." |
| 58 | + $(MAKE) -C $(WHISPER_CPP_DIR) -j$$(nproc) |
| 59 | + @echo "[+] Build complete." |
| 60 | + @ls $(WHISPER_CPP_DIR)/main $(WHISPER_CPP_DIR)/build/bin/whisper-cli 2>/dev/null | head -1 | xargs -I{} echo "[+] Binary: {}" |
| 61 | + |
| 62 | +.PHONY: whisper-cpp-model |
| 63 | +whisper-cpp-model: ## Download whisper.cpp model (WHISPER_MODEL=base|tiny|small|medium|large-v2) |
| 64 | + @if [ -f "$(WHISPER_MODEL_BIN)" ]; then \ |
| 65 | + echo "[+] Model already exists: $(WHISPER_MODEL_BIN)"; \ |
| 66 | + else \ |
| 67 | + echo "[+] Downloading model: $(WHISPER_MODEL)..."; \ |
| 68 | + bash $(WHISPER_CPP_DIR)/models/download-ggml-model.sh $(WHISPER_MODEL); \ |
| 69 | + fi |
| 70 | + |
| 71 | +.PHONY: whisper-cpp-setup |
| 72 | +whisper-cpp-setup: whisper-cpp-build whisper-cpp-model ## Full whisper.cpp setup (build + model) |
| 73 | + |
| 74 | +# ── Run ─────────────────────────────────────────────────────────────────────── |
| 75 | + |
| 76 | +.PHONY: run |
| 77 | +run: ## Transcribe FILE= or URL= (e.g. make run FILE=video.mp4) |
| 78 | +ifndef FILE |
| 79 | +ifndef URL |
| 80 | + $(error Specify FILE=path/to/video.mp4 or URL=https://...) |
| 81 | +endif |
| 82 | +endif |
| 83 | +ifdef FILE |
| 84 | + $(PY) main.py --file "$(FILE)" --backend $(BACKEND) --language $(LANGUAGE) \ |
| 85 | + --workers $(WORKERS) --output-dir $(OUTPUT) |
| 86 | +endif |
| 87 | +ifdef URL |
| 88 | + $(PY) main.py --url "$(URL)" --backend $(BACKEND) --language $(LANGUAGE) \ |
| 89 | + --workers $(WORKERS) --output-dir $(OUTPUT) |
| 90 | +endif |
| 91 | + |
| 92 | +.PHONY: run-config |
| 93 | +run-config: ## Run using CONFIG= file (default: config.json) |
| 94 | + $(PY) main.py --config $(CONFIG) |
| 95 | + |
| 96 | +.PHONY: dry-run |
| 97 | +dry-run: ## Dry-run — show what would be executed without running |
| 98 | +ifdef FILE |
| 99 | + $(PY) main.py --file "$(FILE)" --backend $(BACKEND) --dry-run |
| 100 | +else ifdef URL |
| 101 | + $(PY) main.py --url "$(URL)" --backend $(BACKEND) --dry-run |
| 102 | +else |
| 103 | + $(error Specify FILE= or URL=) |
| 104 | +endif |
| 105 | + |
| 106 | +.PHONY: run-whisper-cpp |
| 107 | +run-whisper-cpp: ## Run with whisper_cpp backend (auto-detects binary and model) |
| 108 | + $(eval WCPP_BIN := $(shell ls $(WHISPER_CPP_DIR)/build/bin/whisper-cli $(WHISPER_CPP_DIR)/main 2>/dev/null | head -1)) |
| 109 | + @if [ -z "$(WCPP_BIN)" ]; then echo "[x] whisper.cpp binary not found. Run: make whisper-cpp-setup"; exit 1; fi |
| 110 | + @if [ ! -f "$(WHISPER_MODEL_BIN)" ]; then echo "[x] Model not found: $(WHISPER_MODEL_BIN). Run: make whisper-cpp-model"; exit 1; fi |
| 111 | +ifdef FILE |
| 112 | + $(PY) main.py --file "$(FILE)" --backend whisper_cpp \ |
| 113 | + --whisper-binary "$(WCPP_BIN)" --whisper-model "$(WHISPER_MODEL_BIN)" \ |
| 114 | + --language $(LANGUAGE) --workers $(WORKERS) --output-dir $(OUTPUT) |
| 115 | +else ifdef URL |
| 116 | + $(PY) main.py --url "$(URL)" --backend whisper_cpp \ |
| 117 | + --whisper-binary "$(WCPP_BIN)" --whisper-model "$(WHISPER_MODEL_BIN)" \ |
| 118 | + --language $(LANGUAGE) --workers $(WORKERS) --output-dir $(OUTPUT) |
| 119 | +else |
| 120 | + $(error Specify FILE= or URL=) |
| 121 | +endif |
| 122 | + |
| 123 | +.PHONY: run-faster-whisper |
| 124 | +run-faster-whisper: ## Run with faster_whisper backend |
| 125 | + $(MAKE) run BACKEND=faster_whisper |
| 126 | + |
| 127 | +.PHONY: run-openai |
| 128 | +run-openai: ## Run with OpenAI API backend |
| 129 | + $(MAKE) run BACKEND=openai |
| 130 | + |
| 131 | +# ── Output formats ──────────────────────────────────────────────────────────── |
| 132 | + |
| 133 | +.PHONY: run-srt |
| 134 | +run-srt: ## Transcribe and output SRT subtitles |
| 135 | +ifdef FILE |
| 136 | + $(PY) main.py --file "$(FILE)" --backend $(BACKEND) --language $(LANGUAGE) \ |
| 137 | + --format srt --output-dir $(OUTPUT) |
| 138 | +else |
| 139 | + $(error Specify FILE=path/to/video.mp4) |
| 140 | +endif |
| 141 | + |
| 142 | +.PHONY: run-all-formats |
| 143 | +run-all-formats: ## Transcribe and output txt + json + srt + vtt |
| 144 | +ifdef FILE |
| 145 | + $(PY) main.py --file "$(FILE)" --backend $(BACKEND) --language $(LANGUAGE) \ |
| 146 | + --format txt,json,srt,vtt --output-dir $(OUTPUT) |
| 147 | +else |
| 148 | + $(error Specify FILE=path/to/video.mp4) |
| 149 | +endif |
| 150 | + |
| 151 | +# ── Dev ─────────────────────────────────────────────────────────────────────── |
| 152 | + |
| 153 | +.PHONY: check |
| 154 | +check: ## Validate all imports and CLI |
| 155 | + $(PY) -c "from transcriber.config import TranscriptionConfig; print('config OK')" |
| 156 | + $(PY) -c "from transcriber.backends.base import TranscriptionBackend; print('backends OK')" |
| 157 | + $(PY) -c "from transcriber.managers.transcription import TranscriptionManager; print('manager OK')" |
| 158 | + $(PY) -c "from transcriber.formatters.output import OutputFormatter; print('formatter OK')" |
| 159 | + $(PY) main.py --help > /dev/null && echo "CLI OK" |
| 160 | + |
| 161 | +.PHONY: clean |
| 162 | +clean: ## Remove output files and temp dirs |
| 163 | + rm -rf output/* __pycache__ transcriber/__pycache__ |
| 164 | + find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true |
| 165 | + find . -name "*.pyc" -delete |
| 166 | + |
| 167 | +.PHONY: clean-all |
| 168 | +clean-all: clean ## Remove venv and output |
| 169 | + rm -rf $(VENV) |
| 170 | + |
| 171 | +# ── Web interface ───────────────────────────────────────────────────────────── |
| 172 | + |
| 173 | +.PHONY: web |
| 174 | +web: ## Start web interface at http://localhost:8000 |
| 175 | + $(PIP) install --quiet fastapi "uvicorn[standard]" python-multipart |
| 176 | + $(PY) -m uvicorn web.app:app --host 0.0.0.0 --port 8000 --reload |
| 177 | + |
| 178 | +.PHONY: web-install |
| 179 | +web-install: ## Install web dependencies only |
| 180 | + $(PIP) install --quiet fastapi "uvicorn[standard]" python-multipart |
| 181 | + |
| 182 | +# ── Help ────────────────────────────────────────────────────────────────────── |
| 183 | + |
| 184 | +.PHONY: help |
| 185 | +help: ## Show this help |
| 186 | + @echo "" |
| 187 | + @echo " Whisper Transcriber" |
| 188 | + @echo "" |
| 189 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ |
| 190 | + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}' |
| 191 | + @echo "" |
| 192 | + @echo " Variables (override with make VAR=value):" |
| 193 | + @echo " BACKEND $(BACKEND)" |
| 194 | + @echo " LANGUAGE $(LANGUAGE)" |
| 195 | + @echo " WORKERS $(WORKERS)" |
| 196 | + @echo " OUTPUT $(OUTPUT)" |
| 197 | + @echo "" |
| 198 | + @echo " Examples:" |
| 199 | + @echo " make run FILE=video.mp4" |
| 200 | + @echo " make run URL=https://youtube.com/... BACKEND=whisper_cpp LANGUAGE=en" |
| 201 | + @echo " make run-all-formats FILE=video.mp4" |
| 202 | + @echo " make dry-run URL=https://..." |
| 203 | + @echo " make check" |
| 204 | + @echo "" |
0 commit comments