Last active
March 25, 2025 19:52
-
-
Save sebington/eb4aa8ebbc01a6a498792aaa87ff6d67 to your computer and use it in GitHub Desktop.
Transcribe an audio/video file with Groq Whisper
This file contains hidden or 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
from groq import Groq | |
from datetime import timedelta | |
def format_time(seconds): | |
# Ensure the first segment starts at 00:00:00,000 | |
if float(seconds) < 0.001: | |
return "00:00:00,000" | |
time = str(timedelta(seconds=float(seconds))).replace('.', ',')[:-3] | |
return f"{time:0>12}" | |
filename = "bbc_ai_edit.mp3" | |
with open(filename, "rb") as file: | |
segments = Groq().audio.transcriptions.create( | |
file=(filename, file.read()), | |
model="whisper-large-v3-turbo", | |
response_format="verbose_json" | |
).segments | |
with open("subs.srt", 'w') as f: | |
f.writelines(f"{i+1}\n{format_time(s['start'])} --> {format_time(s['end'])}\n{s['text'].strip()}\n\n" | |
for i, s in enumerate(segments)) | |
print("SRT file saved successfully!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment