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

@@ -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 = []