Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bk111 opened this issue Dec 29, 2023 · 1 comment
Open

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

bk111 opened this issue Dec 29, 2023 · 1 comment

Comments

@bk111
Copy link

bk111 commented Dec 29, 2023

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

@nftblackmagic
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants