Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add char limit warn #3130

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions TTS/tts/layers/xtts/tokenizer.py
Original file line number Diff line number Diff line change
@@ -538,8 +538,45 @@ def __init__(self, vocab_file=None):
self.katsu = None
if vocab_file is not None:
self.tokenizer = Tokenizer.from_file(vocab_file)

def check_input_length(self, txt, lang):
char_limits = {
WeberJulian marked this conversation as resolved.
Show resolved Hide resolved
"en": 250,
"de": 198,
"fr": 226,
"es": 206,
"it": 177,
"pt": 166,
"pl": 148,
"zh-cn": 65,
"ar": 115,
"cs": 145,
"ru": 139,
"nl": 162,
"tr": 182,
"ja": 60
}
limit = char_limits.get(lang, 250)

if len(txt) > limit:
print(f"[!] Warning: The text length exceeds the character limit of {limit} for language '{lang}', this might cause truncated audio.")

def preprocess_text(self, txt, lang):
if lang in ["en", "es", "fr", "de", "pt", "it", "pl", "ar", "cs", "ru", "nl", "tr", "zh-cn"]:
WeberJulian marked this conversation as resolved.
Show resolved Hide resolved
txt = multilingual_cleaners(txt, lang)
if lang == "zh-cn":
txt = chinese_transliterate(txt)
elif lang == "ja":
if self.katsu is None:
import cutlet
self.katsu = cutlet.Cutlet()
WeberJulian marked this conversation as resolved.
Show resolved Hide resolved
txt = japanese_cleaners(txt, self.katsu)
else:
raise NotImplementedError()
return txt

def encode(self, txt, lang):
self.check_input_length(txt, lang)
txt = self.preprocess_text(txt, lang)
txt = f"[{lang}]{txt}"
txt = txt.replace(" ", "[SPACE]")