whisper-jax icon indicating copy to clipboard operation
whisper-jax copied to clipboard

Is there some code for Whisper jax to produce srt subtitle?

Open bk111 opened this issue 1 year ago • 1 comments

Is there some code for Whisper jax to produce srt subtitle?

bk111 avatar Dec 29 '23 13:12 bk111

srt_data = ""

for index, entry in enumerate(chunks):
    start_time, end_time = entry['timestamp']
    start_hours, start_minutes, start_seconds = int(start_time // 3600), int((start_time % 3600) // 60), start_time % 60
    end_hours, end_minutes, end_seconds = int(end_time // 3600), int((end_time % 3600) // 60), end_time % 60

    srt_entry = f"{index + 1}\n{start_hours:02d}:{start_minutes:02d}:{start_seconds:06.3f} --> {end_hours:02d}:{end_minutes:02d}:{end_seconds:06.3f}\n{entry['text']}\n\n"

    srt_data += srt_entry

print(srt_data)

with open('output.srt', 'w', encoding='utf-8') as f:
    f.write(srt_data)

print("SRT data saved to output.srt")

I use something like the above

nftblackmagic avatar Jan 05 '24 16:01 nftblackmagic