mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Fixed subtitle splitting before commas
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
- Added new option `Configure silence between chapters` that lets you configure the silence between chapters, mentioned by @lfperez1982 in #79
|
- Added new option `Configure silence between chapters` that lets you configure the silence between chapters, mentioned by @lfperez1982 in #79
|
||||||
- Better indicators while displaying and managing the input and processing files.
|
- Better indicators while displaying and managing the input and processing files.
|
||||||
- Improved the markdown logic to better handle various markdown structures and cases.
|
- Improved the markdown logic to better handle various markdown structures and cases.
|
||||||
|
- Fixed subtitle splitting before commas by combining punctuation with preceding words.
|
||||||
- Fixed save options not working correctly in queue mode, mentioned by @jborza in #78
|
- Fixed save options not working correctly in queue mode, mentioned by @jborza in #78
|
||||||
- Fixed `No Qt platform plugin could be initialized` error, mentioned by @sunrainxyz in #59
|
- Fixed `No Qt platform plugin could be initialized` error, mentioned by @sunrainxyz in #59
|
||||||
- Fixed ordered list numbers not being included in EPUB content conversion. The numbers are now properly included in the converted content, mentioned by @jefro108 in #47
|
- Fixed ordered list numbers not being included in EPUB content conversion. The numbers are now properly included in the converted content, mentioned by @jefro108 in #47
|
||||||
|
|||||||
+23
-21
@@ -1189,13 +1189,32 @@ class ConversionThread(QThread):
|
|||||||
if not tokens_with_timestamps:
|
if not tokens_with_timestamps:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Always combine punctuation with preceding words for consistent handling across modes
|
||||||
|
processed_tokens = []
|
||||||
|
i = 0
|
||||||
|
while i < len(tokens_with_timestamps):
|
||||||
|
token = tokens_with_timestamps[i].copy()
|
||||||
|
|
||||||
|
# Look ahead for punctuation
|
||||||
|
while i + 1 < len(tokens_with_timestamps) and re.match(
|
||||||
|
r"^[^\w\s]+$", tokens_with_timestamps[i + 1]["text"]
|
||||||
|
):
|
||||||
|
token["text"] += tokens_with_timestamps[i + 1]["text"]
|
||||||
|
token["end"] = tokens_with_timestamps[i + 1]["end"]
|
||||||
|
token["whitespace"] = tokens_with_timestamps[i + 1]["whitespace"]
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
processed_tokens.append(token)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# Use processed_tokens instead of tokens_with_timestamps for the rest of the method
|
||||||
if self.subtitle_mode == "Sentence + Highlighting":
|
if self.subtitle_mode == "Sentence + Highlighting":
|
||||||
# Sentence-based processing with karaoke highlighting
|
# Sentence-based processing with karaoke highlighting
|
||||||
separator = r"[.!?]"
|
separator = r"[.!?]"
|
||||||
current_sentence = []
|
current_sentence = []
|
||||||
word_count = 0
|
word_count = 0
|
||||||
|
|
||||||
for token in tokens_with_timestamps:
|
for token in processed_tokens: # Updated to use processed_tokens
|
||||||
current_sentence.append(token)
|
current_sentence.append(token)
|
||||||
word_count += 1
|
word_count += 1
|
||||||
|
|
||||||
@@ -1249,7 +1268,7 @@ class ConversionThread(QThread):
|
|||||||
current_sentence = []
|
current_sentence = []
|
||||||
word_count = 0
|
word_count = 0
|
||||||
|
|
||||||
for token in tokens_with_timestamps:
|
for token in processed_tokens: # Updated to use processed_tokens
|
||||||
current_sentence.append(token)
|
current_sentence.append(token)
|
||||||
word_count += 1
|
word_count += 1
|
||||||
|
|
||||||
@@ -1299,25 +1318,7 @@ class ConversionThread(QThread):
|
|||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
word_count = 1
|
word_count = 1
|
||||||
|
|
||||||
# Combine punctuation with preceding words
|
# Group words into subtitle entries (processed_tokens already has punctuation combined)
|
||||||
processed_tokens = []
|
|
||||||
i = 0
|
|
||||||
while i < len(tokens_with_timestamps):
|
|
||||||
token = tokens_with_timestamps[i].copy()
|
|
||||||
|
|
||||||
# Look ahead for punctuation
|
|
||||||
while i + 1 < len(tokens_with_timestamps) and re.match(
|
|
||||||
r"^[^\w\s]+$", tokens_with_timestamps[i + 1]["text"]
|
|
||||||
):
|
|
||||||
token["text"] += tokens_with_timestamps[i + 1]["text"]
|
|
||||||
token["end"] = tokens_with_timestamps[i + 1]["end"]
|
|
||||||
token["whitespace"] = tokens_with_timestamps[i + 1]["whitespace"]
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
processed_tokens.append(token)
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
# Group words into subtitle entries
|
|
||||||
for i in range(0, len(processed_tokens), word_count):
|
for i in range(0, len(processed_tokens), word_count):
|
||||||
group = processed_tokens[i : i + word_count]
|
group = processed_tokens[i : i + word_count]
|
||||||
if group:
|
if group:
|
||||||
@@ -1334,6 +1335,7 @@ class ConversionThread(QThread):
|
|||||||
if end is None or end <= start or end <= 0:
|
if end is None or end <= start or end <= 0:
|
||||||
subtitle_entries[-1] = (start, fallback_end_time, text)
|
subtitle_entries[-1] = (start, fallback_end_time, text)
|
||||||
|
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
self.cancel_requested = True
|
self.cancel_requested = True
|
||||||
self.should_cancel = True
|
self.should_cancel = True
|
||||||
|
|||||||
Reference in New Issue
Block a user