fixed a bug

This commit is contained in:
2026-09-12 21:27:51 +08:00
parent 55d6860cc0
commit 5856832eca
5 changed files with 247 additions and 17 deletions

View File

@@ -323,3 +323,61 @@ def test_reprocess_without_moss_clears_original_segments(tmp_path, monkeypatch):
VideoProcessor(settings, repository, UnavailableTranscriber()).process(VIDEO_HASH)
assert repository.get_moss_segments(VIDEO_HASH) == []
def test_mark_processing_clears_previous_sentence_data(tmp_path):
repository = VideoRepository(tmp_path / "oral.sqlite3")
repository.upsert_upload(
video_hash=VIDEO_HASH,
title="MOSS lesson",
filename="lesson.mp4",
stored_filename=f"{VIDEO_HASH}.mp4",
content_type="video/mp4",
size_bytes=5,
language="en",
)
repository.save_processing_result(
SentenceBoundaryDocument(
video_hash=VIDEO_HASH,
duration_ms=2400,
algorithm_version=MOSS_ALGORITHM_VERSION,
sentences=[
SentenceBoundary(
index=0,
start_ms=0,
end_ms=1200,
text="Old first.",
language="en",
reference_speech_duration_ms=1000,
),
SentenceBoundary(
index=1,
start_ms=1200,
end_ms=2400,
text="Old second.",
language="en",
reference_speech_duration_ms=1000,
),
],
),
"Old first. Old second.",
moss_segments=[
{
"start_seconds": 0.0,
"end_seconds": 1.2,
"text": "Old first.",
"speaker": "S01",
}
],
)
repository.mark_processing(VIDEO_HASH)
video = repository.get_video(VIDEO_HASH)
document = repository.get_document(VIDEO_HASH)
assert video["status"] == "processing"
assert video["transcription"] is None
assert video["sentence_count"] == 0
assert document is not None
assert document.sentences == []
assert repository.get_moss_segments(VIDEO_HASH) == []

View File

@@ -423,6 +423,36 @@ def test_split_sentences_ignores_am_pm_abbreviations():
]
def test_split_sentences_ignores_clock_times_with_pm_period():
compact = TranscriptionSegment(
start_seconds=0.0,
end_seconds=6.0,
text="The briefing is at 3:00 PM. Eastern officials will attend later.",
)
assert [s.text for s in split_sentences_at_punctuation([compact])] == [
"The briefing is at 3:00 PM. Eastern officials will attend later."
]
spoken = TranscriptionSegment(
start_seconds=0.0,
end_seconds=6.0,
text="We start at 5 pm. Eastern time and then break.",
)
assert [s.text for s in split_sentences_at_punctuation([spoken])] == [
"We start at 5 pm. Eastern time and then break."
]
morning = TranscriptionSegment(
start_seconds=0.0,
end_seconds=6.0,
text="It begins at 9:30 AM. Please arrive early.",
)
assert [s.text for s in split_sentences_at_punctuation([morning])] == [
"It begins at 9:30 AM.",
"Please arrive early.",
]
def test_split_sentences_merges_segment_ending_with_abbreviation():
segments = [
TranscriptionSegment(0.0, 5.0, "The meeting ends at 5 p.m."),
@@ -460,6 +490,77 @@ def test_split_sentences_ignores_common_abbreviations():
]
def test_split_sentences_merges_same_speaker_line_wraps():
segments = [
TranscriptionSegment(
11.18,
15.45,
"[S01]Let's begin with some scheduling announcements for the remainder of President Trump's very",
),
TranscriptionSegment(15.45, 16.29, "[S01]busy week."),
TranscriptionSegment(
16.29,
21.8,
"[S01]Today at 3:00 PM, President Trump will host a Black History Month reception in the East",
),
TranscriptionSegment(21.8, 23.29, "[S01]Room of the White House."),
]
sentences = split_sentences_at_punctuation(segments)
assert [s.text for s in sentences] == [
(
"Let's begin with some scheduling announcements for the remainder of "
"President Trump's very busy week."
),
(
"Today at 3:00 PM, President Trump will host a Black History Month "
"reception in the East Room of the White House."
),
]
assert sentences[0].start_seconds == 11.18
assert sentences[0].end_seconds == 16.29
assert sentences[1].start_seconds == 16.29
assert sentences[1].end_seconds == 23.29
def test_split_sentences_splits_when_speaker_changes():
segments = [
TranscriptionSegment(4.63, 5.93, "[S01]Hello, everybody."),
TranscriptionSegment(6.0, 6.53, "[S02]Hello."),
TranscriptionSegment(6.56, 7.83, "[S01]Good afternoon."),
]
sentences = split_sentences_at_punctuation(segments)
assert [s.text for s in sentences] == [
"Hello, everybody.",
"Hello.",
"Good afternoon.",
]
def test_split_sentences_keeps_same_speaker_sentences_apart():
segments = [
TranscriptionSegment(6.56, 7.83, "[S01]Good afternoon."),
TranscriptionSegment(7.93, 9.86, "[S01]Thank you for your patience, as always."),
]
sentences = split_sentences_at_punctuation(segments)
assert [s.text for s in sentences] == [
"Good afternoon.",
"Thank you for your patience, as always.",
]
def test_split_sentences_ignores_initials_and_version_numbers():
segment = TranscriptionSegment(
start_seconds=0.0,
end_seconds=8.0,
text="Donald J. Trump discussed version 1.9 today. Then the meeting ended.",
)
sentences = split_sentences_at_punctuation([segment])
assert [s.text for s in sentences] == [
"Donald J. Trump discussed version 1.9 today.",
"Then the meeting ended.",
]
def test_post_audio_requests_word_timestamps_and_falls_back(monkeypatch):
calls = []