Last active
July 1, 2024 12:54
-
-
Save assafmo/cf93cfac93be600e1780ff8ed95f988f to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# Usage: ./whisper3-json-to-srt.py output.json > output.srt | |
import sys | |
import json | |
if len(sys.argv) > 1 and sys.argv[1] != '-': | |
with open(sys.argv[1]) as file: | |
data = json.load(file) | |
else: | |
data = json.load(sys.stdin) | |
for i, item in enumerate(data, start=1): | |
start_time = "{:02d}:{:02d}:{:02d},{:03d}".format(int(item['start'] // 3600), int(item['start'] % 3600 // 60), int(item['start'] % 60), int((item['start'] % 1) * 1000)) | |
end_time = "{:02d}:{:02d}:{:02d},{:03d}".format(int(item['end'] // 3600), int(item['end'] % 3600 // 60), int(item['end'] % 60), int((item['end'] % 1) * 1000)) | |
print("{}\n{} --> {}\n{}\n\n".format(i, start_time, end_time, item['text'].strip())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment