Update pipeline/postprocess.py
Browse files- pipeline/postprocess.py +10 -4
pipeline/postprocess.py
CHANGED
|
@@ -38,12 +38,18 @@ def merge_segments(segments: list) -> list:
|
|
| 38 |
combined_duration = seg["end"] - current["start"]
|
| 39 |
ends_sentence = current["text"].rstrip().endswith((".", "!", "?"))
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
should_merge = (
|
| 42 |
-
|
| 43 |
and combined_duration <= MAX_DISPLAY
|
| 44 |
-
and
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
if should_merge:
|
| 49 |
current["text"] = combined_text
|
|
|
|
| 38 |
combined_duration = seg["end"] - current["start"]
|
| 39 |
ends_sentence = current["text"].rstrip().endswith((".", "!", "?"))
|
| 40 |
|
| 41 |
+
# segment کوتاه — همیشه merge کن
|
| 42 |
+
current_words = current.get("words", [])
|
| 43 |
+
is_short = len(current_words) <= 2 or (current["end"] - current["start"]) < 0.8
|
| 44 |
+
|
| 45 |
should_merge = (
|
| 46 |
+
not ends_sentence
|
| 47 |
and combined_duration <= MAX_DISPLAY
|
| 48 |
+
and (
|
| 49 |
+
is_short # segment کوتاه رو همیشه merge کن
|
| 50 |
+
or (len(combined_text) <= MERGE_MAX_CHARS and gap <= MAX_GAP)
|
| 51 |
+
)
|
| 52 |
+
)
|
| 53 |
|
| 54 |
if should_merge:
|
| 55 |
current["text"] = combined_text
|