Whisper Subtitle Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install the following dependencies to make this work.