Skip to content

Instantly share code, notes, and snippets.

Last active November 5, 2023 21:29
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Whisper Subtitle Generator
import sys
import whisper
from whisper.utils import write_srt
def run(input_path: str, output_path: str) -> None:
model = whisper.load_model("base")
result = model.transcribe(input_path)
with open(output_path, "w", encoding="utf-8") as srt_file:
write_srt(result["segments"], file=srt_file)
def main() -> None:
if len(sys.argv) != 3:
"Error: Invalid number of arguments.\n"
"Usage: python <input-path> <output-path>\n"
"Example: python 'video.mp4' ''"
run(input_path=sys.argv[1], output_path=sys.argv[2])
if __name__ == "__main__":
Copy link

Install the following dependencies to make this work.

brew install ffmpeg
pip install git+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment