Files
autoclip/scripts
周小舟 6e59f40f01 feat: in-app Whisper (faster-whisper) — opt-in install + model management
Videos without embedded subtitles (e.g. B站 without AI字幕) need Whisper to
generate subtitles, but bundling it would bloat every install. Instead let
users install it on demand from Settings → 语音识别, and pick which model.

Backend uses faster-whisper (CTranslate2, no PyTorch, ~214MB installed, several
times faster than openai-whisper, cross-platform) — chosen over mlx-whisper,
which hard-depends on torch (~2-3GB).

- whisper_runtime.py (new): pip-install faster-whisper into a user-writable dir
  (<data>/whisper-runtime) using the bundled Python; add to sys.path; status +
  coarse progress; uninstall. Never writes into the signed .app bundle.
- whisper_model_manager.py: tiny→large-v3 from Systran/faster-whisper-*,
  background download via huggingface_hub, real status; cache under
  <data>/whisper-models.
- speech_recognizer.py: subtitle generation rewritten from the `whisper` CLI to
  faster-whisper's WhisperModel API → SRT; availability = runtime installed.
- speech_recognition.py API: /whisper/install, /whisper/uninstall,
  /whisper/runtime-status (+ existing /whisper-models*).
- SpeechRecognitionConfig.tsx: was a stub; now a full UI (install button +
  progress + log, model list with download/delete/status) wired to a new
  speechApi in services/api.ts.
- build_macos_arm.sh: allowlist faster_whisper/ctranslate2/huggingface_hub in
  the dependency guard (they're installed at runtime, imported lazily).

Verified end-to-end: install runtime → download tiny model → transcribe a real
video into a valid SRT, all through the API/runtime.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 01:06:26 +08:00
..

scripts/

构建与运维脚本。桌面客户端只有一条打包路线python-build-standalone下称 PBS 历史上的 PyInstaller / prepare_resources 路线及其脚本已全部移除。

脚本清单

脚本 用途
build_macos_arm.sh 唯一的桌面打包脚本macOS Apple Silicon。端到端产出 .app + .dmg
verify_desktop.sh 后端冒烟测试:cargo check + 起后端,校验 /health/api/v1/video-categories。被 nightly-desktop-smoke.yml 调用。
monitor_whisper.py 运行期 Whisper 任务监控,被根目录 start_autoclip.sh / check_whisper_status.sh 调用。

打包桌面客户端macOS arm64

./scripts/build_macos_arm.sh

产物:

src-tauri/target/release/bundle/macos/
├── AutoClip Desktop.app
└── AutoClip Desktop_1.0.0_aarch64.dmg

这个脚本做了什么

  1. 下载便携 Python 运行时python-build-standalone缓存在 build/pbs-cache/
  2. 用便携 Python 安装 requirements.txt 的全部依赖
  3. 依赖完整性检查AST 扫描后端所有第三方 import缺任何一个就让构建失败 (防止"开发机能跑、打包就 500"
  4. rsync 拷贝后端源码到 src-tauri/resources/backend/
  5. 下载静态 ffmpeg + ffprobearm64自包含零 homebrew 依赖,缓存在 build/ffmpeg-cache/
  6. 构建前端(npm ci && npm run build
  7. cargo tauri build --bundles app
  8. python/backend/ffmpeg/ 注入 .app/Contents/Resources/resources/
  9. ad-hoc 签名 + hdiutil 手动打 DMG

前置依赖

  • Node.js 18+、Rustaarch64-apple-darwin target、cargo-tauri (cargo install tauri-cli)
  • 系统 不需要 预装 Python / ffmpeg —— 脚本会自带便携版

环境变量

  • PIP_INDEX_URLpip 源默认清华镜像CI 里设为 https://pypi.org/simple

CI

.github/workflows/desktop-build.ymlworkflow_dispatchv* tag 上跑同一个 build_macos_arm.sh,打 tag 时把 DMG 挂到 GitHub Release。

当前仅 macOS arm64。PBS 与静态 ffmpeg 对 Intel/Windows/Linux 都有对应版本, 后续把 runner、下载 URL、tauri target 参数化即可泛化。

开发模式(不打包)

直接用 Tauri 开发模式,热重载:

cd src-tauri && cargo tauri dev

(前端 :3000 + 后端动态端口,由 backend_manager.rs 拉起)