Skip to content

Instantly share code, notes, and snippets.

@yasinuygun
Last active July 29, 2023 13:14
  • Star 6 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
Embed
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:
print(
"Error: Invalid number of arguments.\n"
"Usage: python whisper_subtitle_generator.py <input-path> <output-path>\n"
"Example: python whisper_subtitle_generator.py 'video.mp4' 'subtitle.srt'"
)
sys.exit(1)
run(input_path=sys.argv[1], output_path=sys.argv[2])
if __name__ == "__main__":
main()
@yasinuygun
Copy link
Author

Install the following dependencies to make this work.

brew install ffmpeg
pip install git+https://github.com/openai/whisper.git

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