Spaces:
Running
Running
jhj0517
commited on
Commit
·
895b517
1
Parent(s):
28dc833
Fix LRC word translation
Browse files
modules/utils/subtitle_manager.py
CHANGED
|
@@ -8,7 +8,7 @@ import zlib
|
|
| 8 |
from typing import Callable, List, Optional, TextIO, Union, Dict, Tuple
|
| 9 |
from datetime import datetime
|
| 10 |
|
| 11 |
-
from modules.whisper.data_classes import Segment
|
| 12 |
from .files_manager import read_file
|
| 13 |
|
| 14 |
|
|
@@ -323,15 +323,20 @@ class WriteLRC(SubtitlesWriter):
|
|
| 323 |
lines = block.strip()
|
| 324 |
pattern = r'(\[.*?\])'
|
| 325 |
parts = re.split(pattern, lines)
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
return segments
|
| 337 |
|
|
|
|
| 8 |
from typing import Callable, List, Optional, TextIO, Union, Dict, Tuple
|
| 9 |
from datetime import datetime
|
| 10 |
|
| 11 |
+
from modules.whisper.data_classes import Segment, Word
|
| 12 |
from .files_manager import read_file
|
| 13 |
|
| 14 |
|
|
|
|
| 323 |
lines = block.strip()
|
| 324 |
pattern = r'(\[.*?\])'
|
| 325 |
parts = re.split(pattern, lines)
|
| 326 |
+
parts = [part.strip() for part in parts if part]
|
| 327 |
+
|
| 328 |
+
for i, part in enumerate(parts):
|
| 329 |
+
sentence_i = i%2
|
| 330 |
+
if sentence_i == 1:
|
| 331 |
+
start_str, text, end_str = parts[sentence_i-1], parts[sentence_i], parts[sentence_i+1]
|
| 332 |
+
start_str, end_str = start_str.replace("[", "").replace("]", ""), end_str.replace("[", "").replace("]", "")
|
| 333 |
+
start, end = time_str_to_seconds(start_str, self.decimal_marker), time_str_to_seconds(end_str, self.decimal_marker)
|
| 334 |
+
|
| 335 |
+
segments.append(Segment(
|
| 336 |
+
start=start,
|
| 337 |
+
end=end,
|
| 338 |
+
text=text,
|
| 339 |
+
))
|
| 340 |
|
| 341 |
return segments
|
| 342 |
|