This commit is contained in:
Kovid Goyal 2024-09-03 09:23:52 +05:30
parent c4e4661e21
commit 16120d8b39
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 11 deletions

View File

@ -42,7 +42,7 @@ class MainWindow(MainWindow):
marked_text.append(c.position())
if not c.movePosition(QTextCursor.MoveOperation.NextWord, QTextCursor.MoveMode.KeepAnchor):
break
marked_text.append(c.selectedText())
marked_text.append(c.selectedText().replace('\u2029', '\n'))
c.setPosition(c.position())
c.setPosition(0)
self.marked_text = marked_text

View File

@ -167,16 +167,18 @@ def split_long_sentences(sentence: str, offset: int, lang: str = 'en', limit: in
def split_into_utterances(text: str, counter: count, lang: str = 'en'):
text = re.sub(r'\n{2,}', PARAGRAPH_SEPARATOR, text.replace('\r', '')).replace('\n', ' ')
for start, length in sentence_positions(text, lang):
sentence = text[start:start+length].rstrip().replace('\n', ' ')
for start, sentence in split_long_sentences(sentence, start, lang):
payload = json.dumps({'text': sentence}).encode('utf-8')
ba = QByteArray()
ba.reserve(len(payload) + 1)
ba.append(payload)
ba.append(UTTERANCE_SEPARATOR)
u = Utterance(id=next(counter), payload_size=len(ba), audio_data=QByteArray(), left_to_write=ba, start=start, length=len(sentence))
debug(f'Utterance created {u.id}: {sentence}')
yield u
sentence = text[start:start+length].rstrip().replace('\n', ' ').strip()
if sentence:
for start, sentence in split_long_sentences(sentence, start, lang):
payload = json.dumps({'text': sentence}).encode('utf-8')
ba = QByteArray()
ba.reserve(len(payload) + 1)
ba.append(payload)
ba.append(UTTERANCE_SEPARATOR)
u = Utterance(id=next(counter), payload_size=len(ba), audio_data=QByteArray(),
left_to_write=ba, start=start, length=len(sentence))
debug(f'Utterance created {u.id}: {sentence}')
yield u
class Piper(TTSBackend):