Upload go.py
Browse files
go.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
|
3 |
+
# Cargar el modelo de Whisper
|
4 |
+
model = whisper.load_model("base")
|
5 |
+
|
6 |
+
# Transcribir el archivo WAV
|
7 |
+
result = model.transcribe("entrada.wav")
|
8 |
+
|
9 |
+
# Función para formatear los tiempos en el estilo SRT
|
10 |
+
def format_timestamp(seconds):
|
11 |
+
hours = int(seconds // 3600)
|
12 |
+
minutes = int((seconds % 3600) // 60)
|
13 |
+
seconds = int(seconds % 60)
|
14 |
+
milliseconds = int((seconds % 1) * 1000)
|
15 |
+
return f"{hours:02}:{minutes:02}:{seconds:02},{milliseconds:03}"
|
16 |
+
|
17 |
+
# Guardar la transcripción en formato SRT
|
18 |
+
with open("transcripcion.srt", "w", encoding="utf-8") as srt_file:
|
19 |
+
for i, segment in enumerate(result["segments"]):
|
20 |
+
# Escribe el número del segmento
|
21 |
+
srt_file.write(f"{i + 1}\n")
|
22 |
+
# Escribe el tiempo de inicio y fin
|
23 |
+
start_time = format_timestamp(segment["start"])
|
24 |
+
end_time = format_timestamp(segment["end"])
|
25 |
+
srt_file.write(f"{start_time} --> {end_time}\n")
|
26 |
+
# Escribe el texto
|
27 |
+
srt_file.write(f"{segment['text'].strip()}\n\n")
|
28 |
+
|
29 |
+
|