Skip to content

Instantly share code, notes, and snippets.

@assafmo
Last active July 1, 2024 12:54
Show Gist options
  • Save assafmo/cf93cfac93be600e1780ff8ed95f988f to your computer and use it in GitHub Desktop.
Save assafmo/cf93cfac93be600e1780ff8ed95f988f to your computer and use it in GitHub Desktop.
#!/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