ajust time span

This commit is contained in:
2026-08-18 21:16:43 +08:00
parent 1fb3146590
commit 7556fd0a7e
4 changed files with 19 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ class VideoProcessor:
transcript=transcript,
language=video.get("language"),
audio_path=work_path,
end_padding_ms=self.settings.moss_end_padding_ms,
)
if not document.sentences:
raise RuntimeError("MOSS returned no timestamped speech segments.")
@@ -103,13 +104,23 @@ def document_from_transcript(
transcript: Transcript,
language: Optional[str],
audio_path: Path,
end_padding_ms: int = 300,
) -> SentenceBoundaryDocument:
samples, sample_rate = decode_audio_mono(audio_path)
sentences: List[SentenceBoundary] = []
previous_end = 0
for sentence_segment in split_sentences_at_punctuation(transcript.segments):
sentence_segments = split_sentences_at_punctuation(transcript.segments)
for index, sentence_segment in enumerate(sentence_segments):
start_ms = max(previous_end, int(round(sentence_segment.start_seconds * 1000)))
end_ms = min(duration_ms, int(round(sentence_segment.end_seconds * 1000)))
end_ms = min(
duration_ms,
int(round(sentence_segment.end_seconds * 1000)) + end_padding_ms,
)
if index + 1 < len(sentence_segments):
next_start_ms = int(
round(sentence_segments[index + 1].start_seconds * 1000)
)
end_ms = min(end_ms, next_start_ms)
if not sentence_segment.text.strip() or end_ms <= start_ms:
continue
start_sample = max(0, int(start_ms / 1000 * sample_rate))