From c921a72a571b9178a0636e5eee20d3383cdac2f8 Mon Sep 17 00:00:00 2001 From: Drugsosos <44712637+Drugsosos@users.noreply.github.com> Date: Fri, 15 Jul 2022 01:06:13 +0300 Subject: [PATCH] fixes in text_len_sanitize --- TTS/common.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/TTS/common.py b/TTS/common.py index d4d0200..b0d8898 100644 --- a/TTS/common.py +++ b/TTS/common.py @@ -23,13 +23,32 @@ class BaseApiTTS: Split text as a list """ # Split by comma or dot (else you can lose intonations), if there is non, split by groups of 299 chars - if '.' in text and all([split_text.__len__() < max_length for split_text in text.split('.')]): - return text.split('.') - - if ',' in text and all([split_text.__len__() < max_length for split_text in text.split(',')]): - return text.split(',') - - return [text[i:i + max_length] for i in range(0, len(text), max_length)] + split_text = '' + + split_text = list( + map(lambda x: x.strip() if x.strip()[-1] != '.' else x.strip()[:-1], + filter(lambda x: True if x else False, text.split('.'))) + ) + if split_text and all([chunk.__len__() < max_length for chunk in split_text]): + return split_text + + split_text = list( + map(lambda x: x.strip() if x.strip()[-1] != ',' else x.strip()[:-1], + filter(lambda x: True if x else False, text.split(',')) + ) + ) + if split_text and all([chunk.__len__() < max_length for chunk in split_text]): + return split_text + + return list( + map( + lambda x: x.strip() if x.strip()[-1] != '.' or x.strip()[-1] != ',' else x.strip()[:-1], + filter( + lambda x: True if x else False, + [text[i:i + max_length] for i in range(0, len(text), max_length)] + ) + ) + ) def write_file( self,