|
import whisper
|
|
|
|
|
|
model = whisper.load_model("base")
|
|
|
|
|
|
result = model.transcribe("entrada.wav")
|
|
|
|
|
|
def format_timestamp(seconds):
|
|
hours = int(seconds // 3600)
|
|
minutes = int((seconds % 3600) // 60)
|
|
seconds = int(seconds % 60)
|
|
milliseconds = int((seconds % 1) * 1000)
|
|
return f"{hours:02}:{minutes:02}:{seconds:02},{milliseconds:03}"
|
|
|
|
|
|
with open("transcripcion.srt", "w", encoding="utf-8") as srt_file:
|
|
for i, segment in enumerate(result["segments"]):
|
|
|
|
srt_file.write(f"{i + 1}\n")
|
|
|
|
start_time = format_timestamp(segment["start"])
|
|
end_time = format_timestamp(segment["end"])
|
|
srt_file.write(f"{start_time} --> {end_time}\n")
|
|
|
|
srt_file.write(f"{segment['text'].strip()}\n\n")
|
|
|
|
|
|
|