AliJabbarpour commited on
Commit
9f46420
·
verified ·
1 Parent(s): 47de646

Update pipeline/postprocess.py

Browse files
Files changed (1) hide show
  1. pipeline/postprocess.py +5 -4
pipeline/postprocess.py CHANGED
@@ -3,7 +3,7 @@
3
  MIN_DISPLAY = 2.5
4
  MAX_DISPLAY = 7.0
5
  MERGE_MAX_CHARS = 72
6
- SPLIT_MAX_CHARS = 60
7
  MAX_GAP = 1.5
8
 
9
 
@@ -108,11 +108,12 @@ def apply_min_display(segments: list) -> list:
108
  return result
109
 
110
 
111
- def split_long_segment(seg: dict) -> list:
112
  words = seg.get("words", [])
113
  text = seg["text"].strip()
114
 
115
- if len(text) <= SPLIT_MAX_CHARS or len(words) < 3:
 
116
  return [seg]
117
 
118
  best_idx = len(words) // 2
@@ -145,7 +146,7 @@ def split_long_segment(seg: dict) -> list:
145
  "words": words2,
146
  }
147
 
148
- return split_long_segment(seg1) + split_long_segment(seg2)
149
 
150
 
151
  def build_srt(segments: list) -> str:
 
3
  MIN_DISPLAY = 2.5
4
  MAX_DISPLAY = 7.0
5
  MERGE_MAX_CHARS = 72
6
+ SPLIT_MAX_CHARS = 80
7
  MAX_GAP = 1.5
8
 
9
 
 
108
  return result
109
 
110
 
111
+ def split_long_segment(seg: dict, depth: int = 0) -> list:
112
  words = seg.get("words", [])
113
  text = seg["text"].strip()
114
 
115
+ # حداکثر ۲ بار split — جلوگیری از تک کلمه شدن
116
+ if depth >= 2 or len(text) <= SPLIT_MAX_CHARS or len(words) < 4:
117
  return [seg]
118
 
119
  best_idx = len(words) // 2
 
146
  "words": words2,
147
  }
148
 
149
+ return split_long_segment(seg1, depth + 1) + split_long_segment(seg2, depth + 1)
150
 
151
 
152
  def build_srt(segments: list) -> str: