2020-03-05 20:44:47 +00:00
import os
2021-04-12 09:47:39 +00:00
2020-03-05 20:44:47 +00:00
# pylint: disable=unused-wildcard-import
# pylint: disable=wildcard-import
# pylint: disable=unused-import
2021-04-12 09:47:39 +00:00
from tests import get_tests_input_path , get_tests_path
2020-09-09 10:27:23 +00:00
from TTS . tts . utils . text import *
from TTS . utils . io import load_config
2020-03-05 20:44:47 +00:00
2021-04-12 09:47:39 +00:00
conf = load_config ( os . path . join ( get_tests_input_path ( ) , " test_config.json " ) )
2019-03-27 13:56:40 +00:00
def test_phoneme_to_sequence ( ) :
2020-10-26 20:41:23 +00:00
2019-03-27 13:56:40 +00:00
text = " Recent research at Harvard has shown meditating for as little as 8 weeks can actually increase, the grey matter in the parts of the brain responsible for emotional regulation and learning! "
text_cleaner = [ " phoneme_cleaners " ]
lang = " en-us "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
2021-03-08 15:08:23 +00:00
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters )
2020-03-05 20:44:47 +00:00
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters )
2021-04-12 09:47:39 +00:00
gt = " ɹiː sənt ɹᵻsɜː tʃ æt hɑ ː ɹvɚd hɐz ʃoʊn mɛdᵻteɪ ɾɪ ŋ fɔː ɹ æz lɪ ɾəl æz eɪ t wiː ks kæn æktʃuː əli ɪ ŋkɹiː s, ðə ɡ ɹeɪ mæɾɚɹ ɪ nðə pɑ ː ɹts ʌvðə bɹeɪ n ɹᵻspɑ ː nsᵻbəl fɔː ɹ ɪ moʊʃənəl ɹɛɡ jʊleɪ ʃən ænd lɜː nɪ ŋ! "
2020-07-16 13:05:36 +00:00
assert text_hat == text_hat_with_params == gt
2021-02-09 11:43:17 +00:00
2019-03-29 14:42:46 +00:00
# multiple punctuations
text = " Be a voice, not an! echo? "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
2020-08-04 12:07:47 +00:00
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters )
2020-03-05 20:44:47 +00:00
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters )
2021-02-12 14:07:26 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ? "
2019-03-29 14:42:46 +00:00
print ( text_hat )
print ( len ( sequence ) )
2020-03-05 20:44:47 +00:00
assert text_hat == text_hat_with_params == gt
2019-03-29 14:42:46 +00:00
# not ending with punctuation
text = " Be a voice, not an! echo "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
2020-08-04 12:07:47 +00:00
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters )
2020-03-05 20:44:47 +00:00
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters )
2021-02-12 14:07:26 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ "
2019-03-29 14:42:46 +00:00
print ( text_hat )
print ( len ( sequence ) )
2020-03-05 20:44:47 +00:00
assert text_hat == text_hat_with_params == gt
2019-03-29 14:42:46 +00:00
# original
text = " Be a voice, not an echo! "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
2020-08-04 12:07:47 +00:00
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters )
2020-03-05 20:44:47 +00:00
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters )
2019-04-12 14:12:15 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t ɐn ɛkoʊ! "
2019-03-29 14:42:46 +00:00
print ( text_hat )
print ( len ( sequence ) )
2020-03-05 20:44:47 +00:00
assert text_hat == text_hat_with_params == gt
2019-03-29 14:42:46 +00:00
# extra space after the sentence
text = " Be a voice, not an! echo. "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
2020-08-04 12:07:47 +00:00
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters )
2020-03-05 20:44:47 +00:00
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters )
2021-02-12 14:07:26 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ. "
2019-04-12 14:12:15 +00:00
print ( text_hat )
print ( len ( sequence ) )
2020-03-05 20:44:47 +00:00
assert text_hat == text_hat_with_params == gt
2019-04-12 14:12:15 +00:00
# extra space after the sentence
text = " Be a voice, not an! echo. "
sequence = phoneme_to_sequence ( text , text_cleaner , lang , True )
text_hat = sequence_to_phoneme ( sequence )
2020-08-04 12:07:47 +00:00
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters )
2020-03-05 20:44:47 +00:00
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters )
2021-02-12 14:07:26 +00:00
gt = " ^biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ.~ "
2019-03-29 14:42:46 +00:00
print ( text_hat )
print ( len ( sequence ) )
2020-03-05 20:44:47 +00:00
assert text_hat == text_hat_with_params == gt
2019-03-29 14:42:46 +00:00
2019-05-17 14:15:43 +00:00
# padding char
text = " _Be a _voice, not an! echo_ "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
2020-08-04 12:07:47 +00:00
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters )
2020-03-05 20:44:47 +00:00
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters )
2021-02-12 14:07:26 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ "
2019-05-17 14:15:43 +00:00
print ( text_hat )
print ( len ( sequence ) )
2020-03-05 20:44:47 +00:00
assert text_hat == text_hat_with_params == gt
2019-03-27 13:56:40 +00:00
2021-04-12 09:47:39 +00:00
2020-10-26 20:41:23 +00:00
def test_phoneme_to_sequence_with_blank_token ( ) :
text = " Recent research at Harvard has shown meditating for as little as 8 weeks can actually increase, the grey matter in the parts of the brain responsible for emotional regulation and learning! "
text_cleaner = [ " phoneme_cleaners " ]
lang = " en-us "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters , add_blank = True )
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters , add_blank = True )
2021-02-12 14:07:26 +00:00
gt = " ɹiː sənt ɹᵻsɜː tʃ æt hɑ ː ɹvɚd hɐz ʃoʊn mɛdᵻteɪ ɾɪ ŋ fɔː ɹ æz lɪ ɾəl æz eɪ t wiː ks kæn æktʃuː əli ɪ ŋkɹiː s, ðə ɡ ɹeɪ mæɾɚɹ ɪ nðə pɑ ː ɹts ʌvðə bɹeɪ n ɹᵻspɑ ː nsᵻbəl fɔː ɹ ɪ moʊʃənəl ɹɛɡ jʊleɪ ʃən ænd lɜː nɪ ŋ! "
2020-10-26 20:41:23 +00:00
assert text_hat == text_hat_with_params == gt
# multiple punctuations
text = " Be a voice, not an! echo? "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters , add_blank = True )
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters , add_blank = True )
2021-04-12 09:47:39 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ? "
2020-10-26 20:41:23 +00:00
print ( text_hat )
print ( len ( sequence ) )
assert text_hat == text_hat_with_params == gt
# not ending with punctuation
text = " Be a voice, not an! echo "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters , add_blank = True )
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters , add_blank = True )
2021-04-12 09:47:39 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ "
2020-10-26 20:41:23 +00:00
print ( text_hat )
print ( len ( sequence ) )
assert text_hat == text_hat_with_params == gt
# original
text = " Be a voice, not an echo! "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters , add_blank = True )
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters , add_blank = True )
2021-04-12 09:47:39 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t ɐn ɛkoʊ! "
2020-10-26 20:41:23 +00:00
print ( text_hat )
print ( len ( sequence ) )
assert text_hat == text_hat_with_params == gt
# extra space after the sentence
text = " Be a voice, not an! echo. "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters , add_blank = True )
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters , add_blank = True )
2021-04-12 09:47:39 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ. "
2020-10-26 20:41:23 +00:00
print ( text_hat )
print ( len ( sequence ) )
assert text_hat == text_hat_with_params == gt
# extra space after the sentence
text = " Be a voice, not an! echo. "
sequence = phoneme_to_sequence ( text , text_cleaner , lang , True )
text_hat = sequence_to_phoneme ( sequence )
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters , add_blank = True )
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters , add_blank = True )
2021-02-12 14:07:26 +00:00
gt = " ^biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ.~ "
2020-10-26 20:41:23 +00:00
print ( text_hat )
print ( len ( sequence ) )
assert text_hat == text_hat_with_params == gt
# padding char
text = " _Be a _voice, not an! echo_ "
sequence = phoneme_to_sequence ( text , text_cleaner , lang )
text_hat = sequence_to_phoneme ( sequence )
_ = phoneme_to_sequence ( text , text_cleaner , lang , tp = conf . characters , add_blank = True )
text_hat_with_params = sequence_to_phoneme ( sequence , tp = conf . characters , add_blank = True )
2021-02-12 14:07:26 +00:00
gt = " biː ɐ vɔɪ s, nɑ ː t æn! ɛkoʊ "
2020-10-26 20:41:23 +00:00
print ( text_hat )
print ( len ( sequence ) )
assert text_hat == text_hat_with_params == gt
2021-04-12 09:47:39 +00:00
2019-03-27 13:56:40 +00:00
def test_text2phone ( ) :
text = " Recent research at Harvard has shown meditating for as little as 8 weeks can actually increase, the grey matter in the parts of the brain responsible for emotional regulation and learning! "
2021-04-12 09:47:39 +00:00
gt = " ɹ|iː |s|ə|n|t| |ɹ|ᵻ|s|ɜː|tʃ| |æ|t| |h|ɑːɹ|v|ɚ|d| |h|ɐ|z| |ʃ|oʊ|n| |m|ɛ|d|ᵻ|t|eɪ |ɾ|ɪ |ŋ| |f|ɔː|ɹ| |æ|z| |l|ɪ |ɾ|əl| |æ|z| |eɪ |t| |w|iː |k|s| |k|æ|n| |æ|k|tʃ|uː |əl|i| |ɪ |ŋ|k|ɹ|iː |s|,| |ð|ə| |ɡ |ɹ|eɪ | |m|æ|ɾ|ɚ|ɹ| |ɪ |n|ð|ə| |p|ɑːɹ|t|s| |ʌ|v|ð|ə| |b|ɹ|eɪ |n| |ɹ|ᵻ|s|p|ɑ ː |n|s|ᵻ|b|əl| |f|ɔː|ɹ| |ɪ |m|oʊ|ʃ|ə|n|əl| |ɹ|ɛ|ɡ |j|ʊ|l|eɪ |ʃ|ə|n| |æ|n|d| |l|ɜː|n|ɪ |ŋ|! "
2019-03-27 13:56:40 +00:00
lang = " en-us "
2020-02-13 16:23:37 +00:00
ph = text2phone ( text , lang )
2020-12-10 15:37:54 +00:00
assert gt == ph