Finaliza os ajustes para render de video
This commit is contained in:
@@ -118,5 +118,75 @@ class TranscriptionService:
|
||||
with text_path.open("w", encoding="utf-8") as fp:
|
||||
fp.write(result.full_text)
|
||||
|
||||
logger.info("Transcrição salva em %s", destination)
|
||||
logger.info("Transcricao salva em %s", destination)
|
||||
|
||||
@staticmethod
|
||||
def load(source: Path) -> Optional[TranscriptionResult]:
|
||||
json_path = source / "transcription.json"
|
||||
if not json_path.exists():
|
||||
return None
|
||||
|
||||
try:
|
||||
with json_path.open("r", encoding="utf-8") as fp:
|
||||
payload = json.load(fp)
|
||||
except (OSError, json.JSONDecodeError) as exc:
|
||||
logger.warning(
|
||||
"Falha ao carregar transcricao existente de %s: %s", json_path, exc
|
||||
)
|
||||
return None
|
||||
|
||||
segments_payload = payload.get("segments", [])
|
||||
if not isinstance(segments_payload, list):
|
||||
logger.warning(
|
||||
"Formato inesperado ao carregar transcricao de %s: 'segments' invalido",
|
||||
json_path,
|
||||
)
|
||||
return None
|
||||
|
||||
segments: List[TranscriptSegment] = []
|
||||
for idx, segment_data in enumerate(segments_payload):
|
||||
if not isinstance(segment_data, dict):
|
||||
logger.debug("Segmento invalido ignorado ao carregar: %s", segment_data)
|
||||
continue
|
||||
try:
|
||||
segment_id = int(segment_data.get("id", idx))
|
||||
start = float(segment_data["start"])
|
||||
end = float(segment_data["end"])
|
||||
except (KeyError, TypeError, ValueError):
|
||||
logger.debug("Segmento sem dados obrigatorios ignorado: %s", segment_data)
|
||||
continue
|
||||
|
||||
text = str(segment_data.get("text", "")).strip()
|
||||
words_payload = segment_data.get("words", [])
|
||||
words: List[WordTiming] = []
|
||||
|
||||
if isinstance(words_payload, list):
|
||||
for word_data in words_payload:
|
||||
if not isinstance(word_data, dict):
|
||||
continue
|
||||
try:
|
||||
w_start = float(word_data["start"])
|
||||
w_end = float(word_data["end"])
|
||||
except (KeyError, TypeError, ValueError):
|
||||
logger.debug(
|
||||
"Palavra sem dados obrigatorios ignorada: %s", word_data
|
||||
)
|
||||
continue
|
||||
word_text = str(word_data.get("text", "")).strip()
|
||||
if not word_text:
|
||||
continue
|
||||
words.append(WordTiming(start=w_start, end=w_end, word=word_text))
|
||||
|
||||
segments.append(
|
||||
TranscriptSegment(
|
||||
id=segment_id,
|
||||
start=start,
|
||||
end=end,
|
||||
text=text,
|
||||
words=words,
|
||||
)
|
||||
)
|
||||
|
||||
full_text = str(payload.get("full_text", "")).strip()
|
||||
return TranscriptionResult(segments=segments, full_text=full_text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user