From 85a1990cc6ff843f4ebdd7faf8ede3e62d703524 Mon Sep 17 00:00:00 2001 From: Eren Golge Date: Tue, 1 Jan 2019 20:10:06 +0100 Subject: [PATCH] Convesntional update s --- utils/text/__init__.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/utils/text/__init__.py b/utils/text/__init__.py index bbde1d04..dce66c94 100644 --- a/utils/text/__init__.py +++ b/utils/text/__init__.py @@ -67,22 +67,39 @@ def sequence_to_phoneme(sequence): return result.replace('}{', ' ') -def phonem_to_sequence(text, cleaner_names): +def phoneme_to_sequence(text, cleaner_names): ''' TODO: This ignores punctuations ''' sequence = [] clean_text = _clean_text(text, cleaner_names) for word in clean_text.split(): - phonems_text = text2phone(word) - if phonems_text == None: + phonemes_text = text2phone(word) + if phonemes_text == None: + print("!! After phoneme conversion the result is None. -- {} ".format(word)) continue - sequence += _phonem_to_sequence(phonems_text) + sequence += _phoneme_to_sequence(phonemes_text) + if word[0] in _punctuations: + sequence.append(_phonemes_to_id[word[0]]) + elif word[-1] in _punctuations: + sequence.append(_phonemes_to_id[word[-1]]) sequence.append(_phonemes_to_id[' ']) + # Aeepnd EOS char sequence.append(_phonemes_to_id['~']) return sequence +def sequence_to_phoneme(sequence): + '''Converts a sequence of IDs back to a string''' + result = '' + for symbol_id in sequence: + if symbol_id in _id_to_phonemes: + s = _id_to_phonemes[symbol_id] + print(s) + result += s + return result.replace('}{', ' ') + + def text_to_sequence(text, cleaner_names): '''Converts a string of text to a sequence of IDs corresponding to the symbols in the text. @@ -127,17 +144,6 @@ def sequence_to_text(sequence): return result.replace('}{', ' ') -def sequence_to_phonem(sequence): - '''Converts a sequence of IDs back to a string''' - result = '' - for symbol_id in sequence: - if symbol_id in _id_to_phonemes: - s = _id_to_phonemes[symbol_id] - print(s) - result += s - return result.replace('}{', ' ') - - def _clean_text(text, cleaner_names): for name in cleaner_names: cleaner = getattr(cleaners, name) @@ -151,6 +157,7 @@ def _symbols_to_sequence(symbols): return [_symbol_to_id[s] for s in symbols if _should_keep_symbol(s)] +<<<<<<< HEAD <<<<<<< HEAD def _phoneme_to_sequence(phonemes): return [_phonemes_to_id[s] for s in list(phonemes) if _should_keep_phoneme(s)] @@ -158,6 +165,10 @@ def _phoneme_to_sequence(phonemes): def _phonem_to_sequence(phonemes): return [_phonemes_to_id[s] for s in phonemes.split(" ") if _should_keep_phonem(s)] >>>>>>> phonem updates +======= +def _phoneme_to_sequence(phonemes): + return [_phonemes_to_id[s] for s in phonemes.split(" ") if _should_keep_phoneme(s)] +>>>>>>> Convesntional update s def _arpabet_to_sequence(text):