Skip to main content

AI-powered subtitle generation from video/audio using Whisper.

Project description

Subtitle Generator

Generate subtitles for video/audio files using whisper.cpp.

PyPI License: MIT Python 3.9+

Install

pip install subtitle-generator
subtitle setup-whisper          # one-time: clones + builds whisper-cli

subtitle setup-whisper needs git, cmake, a C++ compiler, and ffmpeg:

# macOS
xcode-select --install && brew install cmake ffmpeg
# Linux
sudo apt-get install -y build-essential cmake git ffmpeg
# Windows
# Install Git, CMake, VS Build Tools, ffmpeg.

The built binary lands in your per-OS user data dir (e.g. ~/Library/Application Support/subtitle-generator/bin/ on macOS) and is auto-discovered on every subsequent run.

Homebrew's whisper-cpp 1.8.4 dropped the -vi flag we use to ingest video directly, so subtitle setup-whisper is the recommended way to get a compatible binary.

Usage

# VTT (default), output in current directory
subtitle video.mp4

# SRT
subtitle video.mp4 --format srt

# Generate SRT and embed it into the video
# Writes ./video.srt and ./video_subtitled.mp4
subtitle video.mp4 --merge --format srt

# Larger model
subtitle video.mp4 --model large

# Custom output directory
subtitle /path/to/video.mp4 --output-dir ~/subs --format srt

Subcommands

Command Description
subtitle <video> Transcribe and write subtitle file
subtitle <video> --merge Transcribe + mux into a copy of the video
subtitle setup-whisper Build whisper-cli into user data dir (one-time)
subtitle models --list List/check downloaded models
subtitle batch --input-dir <dir> Batch-process a directory
subtitle formats Show supported subtitle formats

Options

Flag Description
--model, -m tiny / base / small / medium / large (default: base)
--format, -f vtt / srt / txt / json / lrc (default: vtt)
--merge Embed subtitles into a copy of the video
--output-dir, -o Output directory (default: current dir)
--threads, -t Whisper.cpp thread count
--whisper-binary Override the auto-discovered whisper-cli path
--models-dir Override the model cache directory
--verbose, -v Verbose output

Python API

from subtitle_generator.core import SubtitleGenerator, WhisperCppTranscriber
from subtitle_generator.models import ModelManager

generator = SubtitleGenerator(
    transcriber=WhisperCppTranscriber(),
    model_manager=ModelManager(),
)
result = generator.generate(
    input_path="video.mp4",
    model_name="base",
    output_format="srt",
)
print(result.output_path if result.success else result.error)

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subtitle_generator-3.0.5.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subtitle_generator-3.0.5-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file subtitle_generator-3.0.5.tar.gz.

File metadata

  • Download URL: subtitle_generator-3.0.5.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for subtitle_generator-3.0.5.tar.gz
Algorithm Hash digest
SHA256 8be0d2e4a54569f59f073129e3733d22fd263e36c78b451a020957c365a71c1a
MD5 7b8afdbfc512bf086d5c019f0171cddd
BLAKE2b-256 f71d326c03da3d6826498fe0dd0ce6fb9fbfe0ae44877d201fcca1938915dde1

See more details on using hashes here.

File details

Details for the file subtitle_generator-3.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for subtitle_generator-3.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6e55de77db8060731edf3a67a92aa3406dde3b0105133a8796646b133f671298
MD5 ab9f513b6fe263627eac4ae701e5c7b8
BLAKE2b-256 c9f8f35b0e8e82c4b17a84cca8681a690bf63468a679d8513921b2988a8eb77a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page