Spaces:
Sleeping
Sleeping
travahacker
commited on
Commit
·
46b613a
1
Parent(s):
872c0c4
feat: timestamps [MM:SS] na transcrição para localizar no vídeo
Browse files
app.py
CHANGED
|
@@ -19,6 +19,16 @@ except ImportError:
|
|
| 19 |
spaces = _Spaces()
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@spaces.GPU(duration=180)
|
| 23 |
def transcrever(audio, modelo: str, idioma: str) -> str:
|
| 24 |
"""Transcreve áudio enviado com Whisper."""
|
|
@@ -57,7 +67,7 @@ def transcrever(audio, modelo: str, idioma: str) -> str:
|
|
| 57 |
"text": seg.text.strip(),
|
| 58 |
})
|
| 59 |
|
| 60 |
-
#
|
| 61 |
PAUSA_PARAGRAFO = 1.5
|
| 62 |
linhas = []
|
| 63 |
prev_end = 0
|
|
@@ -66,7 +76,8 @@ def transcrever(audio, modelo: str, idioma: str) -> str:
|
|
| 66 |
continue
|
| 67 |
if prev_end > 0 and (s["start"] - prev_end) > PAUSA_PARAGRAFO:
|
| 68 |
linhas.append("") # linha em branco = novo parágrafo
|
| 69 |
-
|
|
|
|
| 70 |
prev_end = s["end"]
|
| 71 |
texto = "\n".join(linhas)
|
| 72 |
if not texto:
|
|
|
|
| 19 |
spaces = _Spaces()
|
| 20 |
|
| 21 |
|
| 22 |
+
def _fmt_tempo(segundos: float) -> str:
|
| 23 |
+
"""Formata segundos como MM:SS ou HH:MM:SS."""
|
| 24 |
+
h = int(segundos // 3600)
|
| 25 |
+
m = int((segundos % 3600) // 60)
|
| 26 |
+
s = int(segundos % 60)
|
| 27 |
+
if h > 0:
|
| 28 |
+
return f"{h:01d}:{m:02d}:{s:02d}"
|
| 29 |
+
return f"{m:01d}:{s:02d}"
|
| 30 |
+
|
| 31 |
+
|
| 32 |
@spaces.GPU(duration=180)
|
| 33 |
def transcrever(audio, modelo: str, idioma: str) -> str:
|
| 34 |
"""Transcreve áudio enviado com Whisper."""
|
|
|
|
| 67 |
"text": seg.text.strip(),
|
| 68 |
})
|
| 69 |
|
| 70 |
+
# Timestamp + parágrafos: [MM:SS] texto, linha em branco quando pausa > 1.5s
|
| 71 |
PAUSA_PARAGRAFO = 1.5
|
| 72 |
linhas = []
|
| 73 |
prev_end = 0
|
|
|
|
| 76 |
continue
|
| 77 |
if prev_end > 0 and (s["start"] - prev_end) > PAUSA_PARAGRAFO:
|
| 78 |
linhas.append("") # linha em branco = novo parágrafo
|
| 79 |
+
ts = _fmt_tempo(s["start"])
|
| 80 |
+
linhas.append(f"[{ts}] {s['text']}")
|
| 81 |
prev_end = s["end"]
|
| 82 |
texto = "\n".join(linhas)
|
| 83 |
if not texto:
|