mirror of
https://github.com/modelscope/FunASR.git
synced 2026-10-12 02:19:18 +00:00
Merge pull request #3562 from modelscope/codex/fix-srt-tiny-gap-boundary-20260830
Fix tiny-gap semantic boundaries in readable SRT
This commit is contained in:
@@ -80,6 +80,7 @@ def merge_subtitle_segments(
|
||||
"""Group sentence timestamps into bounded, readable subtitle cues."""
|
||||
def can_follow(left, right):
|
||||
left_text = str(left.get("text", ""))
|
||||
right_text = str(right.get("text", ""))
|
||||
gap_ms = right.get("start", 0) - left.get("end", 0)
|
||||
left_speaker = left.get("speaker", left.get("spk"))
|
||||
right_speaker = right.get("speaker", right.get("spk"))
|
||||
@@ -89,6 +90,13 @@ def merge_subtitle_segments(
|
||||
and (
|
||||
left_text.rstrip().endswith(SUBTITLE_CONTINUATION_PUNCTUATION)
|
||||
or _subtitle_body_length(left_text) <= 2
|
||||
or (
|
||||
gap_ms <= min(max_gap_ms, 100)
|
||||
and _subtitle_body_length(right_text) > 2
|
||||
and right_text.rstrip().endswith(
|
||||
SUBTITLE_CONTINUATION_PUNCTUATION
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -238,6 +238,41 @@ def test_merge_subtitle_segments_keeps_continuation_chain_with_its_ending():
|
||||
]
|
||||
|
||||
|
||||
def test_merge_subtitle_segments_repacks_false_sentence_boundary_after_tiny_gap():
|
||||
segments = [
|
||||
{"start": 148930, "end": 149830, "text": "就在八月二十五日,"},
|
||||
{
|
||||
"start": 150010,
|
||||
"end": 151930,
|
||||
"text": "上汽大通直接向平台发起投诉,",
|
||||
},
|
||||
{
|
||||
"start": 152170,
|
||||
"end": 153970,
|
||||
"text": "投诉对象是那些转述基金会。",
|
||||
},
|
||||
{"start": 154030, "end": 155050, "text": "声明的自媒体文章,"},
|
||||
{
|
||||
"start": 155470,
|
||||
"end": 157330,
|
||||
"text": "上汽大通的投诉内容写的很清楚,",
|
||||
},
|
||||
]
|
||||
|
||||
assert cli.merge_subtitle_segments(segments) == [
|
||||
{
|
||||
"start": 148930,
|
||||
"end": 151930,
|
||||
"text": "就在八月二十五日,上汽大通直接向平台发起投诉,",
|
||||
},
|
||||
{
|
||||
"start": 152170,
|
||||
"end": 157330,
|
||||
"text": "投诉对象是那些转述基金会。声明的自媒体文章,上汽大通的投诉内容写的很清楚,",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_merge_subtitle_segments_groups_two_character_sentence():
|
||||
segments = [
|
||||
{"start": 12450, "end": 12690, "text": "突然。"},
|
||||
|
||||
Reference in New Issue
Block a user