add debug info
This commit is contained in:
@@ -200,15 +200,50 @@ class VideoProcessor:
|
||||
gaps = find_sentence_gaps(document, min_gap_ms)
|
||||
inserted: List[SentenceBoundary] = []
|
||||
transcribed_gaps = 0
|
||||
logger.info(
|
||||
"Gap repair started: video=%s min_gap_ms=%d language=%s gaps=%d "
|
||||
"sentences=%d duration_ms=%d transcriber=%s",
|
||||
video_hash,
|
||||
min_gap_ms,
|
||||
video.get("language") or "auto",
|
||||
len(gaps),
|
||||
len(document.sentences),
|
||||
document.duration_ms,
|
||||
type(self.transcriber).__name__,
|
||||
)
|
||||
if gaps:
|
||||
language = video.get("language")
|
||||
with tempfile.TemporaryDirectory(prefix="gap-repair-") as temp_dir:
|
||||
for gap_index, (raw_start, raw_end) in enumerate(gaps):
|
||||
logger.info(
|
||||
"Gap %d/%d: raw=%d-%dms duration=%dms",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
raw_start,
|
||||
raw_end,
|
||||
raw_end - raw_start,
|
||||
)
|
||||
clipped = _inset_gap(raw_start, raw_end, document.duration_ms)
|
||||
if clipped is None:
|
||||
logger.warning(
|
||||
"Gap %d/%d skipped after inset: raw=%d-%dms",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
raw_start,
|
||||
raw_end,
|
||||
)
|
||||
continue
|
||||
start_ms, end_ms = clipped
|
||||
chunk_path = Path(temp_dir) / f"gap-{gap_index}.wav"
|
||||
logger.info(
|
||||
"Gap %d/%d extracted range=%d-%dms duration=%dms file=%s",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
start_ms,
|
||||
end_ms,
|
||||
end_ms - start_ms,
|
||||
chunk_path,
|
||||
)
|
||||
try:
|
||||
extract_audio_segment(
|
||||
media_path,
|
||||
@@ -219,14 +254,33 @@ class VideoProcessor:
|
||||
samples, sample_rate = decode_audio_mono(chunk_path)
|
||||
metrics = analyze_samples(samples, sample_rate)
|
||||
except (AudioAnalysisError, RuntimeError) as exc:
|
||||
logger.info(
|
||||
logger.warning(
|
||||
"Skipping sentence gap %s-%sms: %s",
|
||||
start_ms,
|
||||
end_ms,
|
||||
exc,
|
||||
exc_info=True,
|
||||
)
|
||||
continue
|
||||
logger.info(
|
||||
"Gap %d/%d audio metrics: duration_ms=%d speech_duration_ms=%d "
|
||||
"internal_silence_ms=%d pause_ratio=%.3f threshold_ms=%d",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
metrics.recording_duration_ms,
|
||||
metrics.speech_duration_ms,
|
||||
metrics.internal_silence_ms,
|
||||
metrics.internal_pause_ratio,
|
||||
GAP_REPAIR_MIN_SPEECH_MS,
|
||||
)
|
||||
if metrics.speech_duration_ms < GAP_REPAIR_MIN_SPEECH_MS:
|
||||
logger.warning(
|
||||
"Gap %d/%d skipped as silence: speech_duration_ms=%d < %d",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
metrics.speech_duration_ms,
|
||||
GAP_REPAIR_MIN_SPEECH_MS,
|
||||
)
|
||||
continue
|
||||
try:
|
||||
transcript = self.transcriber.transcribe(chunk_path, language)
|
||||
@@ -237,8 +291,16 @@ class VideoProcessor:
|
||||
start_ms,
|
||||
end_ms,
|
||||
exc,
|
||||
exc_info=True,
|
||||
)
|
||||
continue
|
||||
logger.info(
|
||||
"Gap %d/%d transcript returned: segments=%d text=%r",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
len(transcript.segments),
|
||||
transcript.text,
|
||||
)
|
||||
gap_document = document_from_transcript(
|
||||
video_hash=video_hash,
|
||||
duration_ms=end_ms - start_ms,
|
||||
@@ -252,12 +314,45 @@ class VideoProcessor:
|
||||
offset_ms=start_ms,
|
||||
limit_end_ms=end_ms,
|
||||
)
|
||||
if not shifted:
|
||||
logger.warning(
|
||||
"Gap %d/%d produced no insertable sentences: "
|
||||
"transcript_segments=%d boundary_sentences=%d range=%d-%dms",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
len(transcript.segments),
|
||||
len(gap_document.sentences),
|
||||
start_ms,
|
||||
end_ms,
|
||||
)
|
||||
for boundary in gap_document.sentences:
|
||||
logger.warning(
|
||||
"Candidate boundary before shift: start=%d end=%d text=%r",
|
||||
boundary.start_ms,
|
||||
boundary.end_ms,
|
||||
boundary.text,
|
||||
)
|
||||
if not shifted:
|
||||
continue
|
||||
transcribed_gaps += 1
|
||||
inserted.extend(shifted)
|
||||
logger.info(
|
||||
"Gap %d/%d produced %d insertable sentences: range=%d-%dms",
|
||||
gap_index + 1,
|
||||
len(gaps),
|
||||
len(shifted),
|
||||
start_ms,
|
||||
end_ms,
|
||||
)
|
||||
|
||||
if not inserted:
|
||||
logger.warning(
|
||||
"Gap repair finished without inserts: video=%s gaps=%d "
|
||||
"transcribed_gaps=%d inserted=0",
|
||||
video_hash,
|
||||
len(gaps),
|
||||
transcribed_gaps,
|
||||
)
|
||||
return {
|
||||
"min_gap_ms": min_gap_ms,
|
||||
"gap_count": len(gaps),
|
||||
@@ -269,6 +364,16 @@ class VideoProcessor:
|
||||
merged = _merge_sentence_lists(document.sentences, inserted)
|
||||
updated = document.model_copy(update={"sentences": merged})
|
||||
saved = self.repository.replace_sentences(updated)
|
||||
logger.info(
|
||||
"Gap repair finished: video=%s gaps=%d transcribed_gaps=%d inserted=%d "
|
||||
"sentences=%d->%d",
|
||||
video_hash,
|
||||
len(gaps),
|
||||
transcribed_gaps,
|
||||
len(saved.sentences) - len(document.sentences),
|
||||
len(document.sentences),
|
||||
len(saved.sentences),
|
||||
)
|
||||
return {
|
||||
"min_gap_ms": min_gap_ms,
|
||||
"gap_count": len(gaps),
|
||||
|
||||
Reference in New Issue
Block a user