change the method of splitting sentences

This commit is contained in:
2026-08-30 09:06:01 +08:00
parent 997bd9eed8
commit abc052e42d
3 changed files with 61 additions and 11 deletions

View File

@@ -287,6 +287,38 @@ def test_split_sentences_splits_at_question_marks():
assert sentences[2].end_seconds == 10.0
def test_split_sentences_splits_at_comma_after_fifty_words():
before_comma = " ".join(f"word{index}" for index in range(1, 51))
after_comma = "This continuation becomes its own sentence."
segment = TranscriptionSegment(
start_seconds=0.0,
end_seconds=55.0,
text=f"{before_comma}, {after_comma}",
)
sentences = split_sentences_at_punctuation([segment])
assert [s.text for s in sentences] == [
f"{before_comma},",
after_comma,
]
assert sentences[0].start_seconds == 0.0
assert sentences[0].end_seconds == sentences[1].start_seconds
assert sentences[1].end_seconds == 55.0
def test_split_sentences_merges_comma_piece_shorter_than_fifty_words():
segment = TranscriptionSegment(
start_seconds=0.0,
end_seconds=5.0,
text="One, two, and three.",
)
sentences = split_sentences_at_punctuation([segment])
assert [s.text for s in sentences] == ["One, two, and three."]
def test_split_sentences_falls_back_to_proportional():
segments = [
TranscriptionSegment(