{"id":20478140,"url":"https://github.com/sixiaolong1117/whisperpythonscript","last_synced_at":"2026-05-07T20:15:18.258Z","repository":{"id":236732291,"uuid":"792835642","full_name":"SIXiaolong1117/WhisperPythonScript","owner":"SIXiaolong1117","description":"一个简单的 Whisper Python 脚本，可以将媒体文件的音频通过 whisper 识别成文字，并通过 pysrt 保存为字幕。","archived":false,"fork":false,"pushed_at":"2024-07-15T09:28:38.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T03:34:26.668Z","etag":null,"topics":["pysrt","python","python3","whisper","whisper-ai"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SIXiaolong1117.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-27T17:27:32.000Z","updated_at":"2024-07-15T09:28:41.000Z","dependencies_parsed_at":"2024-04-28T10:30:07.946Z","dependency_job_id":"b67f0e15-00a0-4974-9d56-2d73bddd4218","html_url":"https://github.com/SIXiaolong1117/WhisperPythonScript","commit_stats":null,"previous_names":["direct5dom/whisperpythonscript","sixiaolong1117/whisperpythonscript"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIXiaolong1117%2FWhisperPythonScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIXiaolong1117%2FWhisperPythonScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIXiaolong1117%2FWhisperPythonScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIXiaolong1117%2FWhisperPythonScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SIXiaolong1117","download_url":"https://codeload.github.com/SIXiaolong1117/WhisperPythonScript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242048578,"owners_count":20063404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pysrt","python","python3","whisper","whisper-ai"],"created_at":"2024-11-15T15:36:45.516Z","updated_at":"2026-05-07T20:15:18.253Z","avatar_url":"https://github.com/SIXiaolong1117.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Whisper Python Script\n\n一个简单的 Whisper Python 脚本，可以将媒体文件的音频通过 `whisper` 识别成文字，并通过 `pysrt` 保存为字幕。现在整理为统一入口，支持 macOS 和 Apple Silicon（M 系列，包括 M5）上的 `mps` 加速。\n\n## 依赖安装\n\n建议使用 Python 3.11 或 3.12。Apple Silicon 上不建议直接使用系统 Python。\n\n```bash\nbrew install python@3.12 ffmpeg\n```\n\n创建虚拟环境并安装依赖：\n\n```bash\ngit clone https://github.com/SIXiaolong1117/WhisperPythonScript.git\ncd WhisperPythonScript\npython3.12 -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\n```\n\n\u003e 第一次运行会下载 Whisper 模型。`large` 模型体积和内存占用较大，如果内存紧张，可以先用 `--model medium` 或 `--model small`。\n\n## 使用方法\n\n### 推荐入口\n\n生成 `.srt` 字幕：\n\n```bash\npython whisper_subtitles.py \u003c媒体文件路径\u003e --language zh-Hans\n```\n\n生成 `.srt` 并封装为 `.mkv`：\n\n```bash\npython whisper_subtitles.py \u003c媒体文件路径\u003e --language zh-Hans --embed\n```\n\n把已有同名 `.srt` 封装到 `.mkv`：\n\n```bash\npython whisper_subtitles.py \u003c媒体文件路径\u003e --subtitle \u003c字幕文件路径\u003e\n```\n\n指定模型、设备和输出路径：\n\n```bash\npython whisper_subtitles.py video.mp4 --language zh --model medium --device auto -o video.srt\n```\n\n`--device auto` 会在 Apple Silicon 上优先使用 `mps`。为了提高稳定性，脚本默认只在 CUDA 上启用 fp16；如果你确认当前 PyTorch/Whisper 组合在 MPS fp16 下表现正常，可以手动使用：\n\n```bash\npython whisper_subtitles.py video.mp4 --device mps --fp16 true\n```\n\n### 兼容旧入口\n\n旧脚本仍然可用：\n\n```bash\npython v2s.py \u003c媒体文件路径\u003e \u003c语言代码（可选）\u003e\npython v2mkv_s.py \u003c媒体文件路径\u003e \u003c语言代码（可选）\u003e\npython s2mkv_s.py \u003c媒体文件路径\u003e\n```\n\n`v2s.py` 只生成字幕，`v2mkv_s.py` 会生成字幕并封装 MKV，`s2mkv_s.py` 会把同名 `.srt` 封装进 MKV。\n\n## 开源许可\n\n[MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsixiaolong1117%2Fwhisperpythonscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsixiaolong1117%2Fwhisperpythonscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsixiaolong1117%2Fwhisperpythonscript/lists"}