def test_segments(): text = 'achi, acho!' expected1 = 'ʌtʃɪ ʌtʃʊ' expected2 = 'ʌtʃɪ, ʌtʃʊ!' expected3 = 'ʌtʃɪ ʌtʃʊ ' expected4 = 'ʌtʃɪ, ʌtʃʊ!' out1 = SegmentsBackend('cree', preserve_punctuation=False).phonemize([text], strip=True)[0] assert out1 == expected1 out2 = SegmentsBackend('cree', preserve_punctuation=True).phonemize([text], strip=True)[0] assert out2 == expected2 out3 = SegmentsBackend('cree', preserve_punctuation=False).phonemize( [text], strip=False)[0] assert out3 == expected3 out4 = SegmentsBackend('cree', preserve_punctuation=True).phonemize([text], strip=False)[0] assert out4 == expected4
def test_separator(): backend = SegmentsBackend('cree') text = 'achi acho' sep = separator.default_separator assert backend.phonemize(text, separator=sep) == u'ʌtʃɪ ʌtʃʊ ' assert backend.phonemize(text, separator=sep, strip=True) == u'ʌtʃɪ ʌtʃʊ'
def test_multiline(): backend = SegmentsBackend('cree') assert backend.phonemize('a') == u'ʌ ' assert backend.phonemize('aa') == u'ʌʌ ' assert backend.phonemize('a\n') == u'ʌ ' assert backend.phonemize('a\na') == u'ʌ \nʌ ' assert backend.phonemize('a\na\n') == u'ʌ \nʌ '
def test_separator_5(): backend = SegmentsBackend('cree') text = 'achi acho' sep = separator.Separator(phone=' ', word='_') assert backend.phonemize(text, separator=sep) == u'ʌ tʃ ɪ _ʌ tʃ ʊ _' assert backend.phonemize(text, separator=sep, strip=True) \ == u'ʌ tʃ ɪ_ʌ tʃ ʊ'
def test_separator_3(): backend = SegmentsBackend('cree') text = 'achi acho' sep = separator.Separator(word=' ', syllable=None, phone='_') assert backend.phonemize(text, separator=sep) == u'ʌ_tʃ_ɪ_ ʌ_tʃ_ʊ_ ' assert backend.phonemize(text, separator=sep, strip=True) \ == u'ʌ_tʃ_ɪ ʌ_tʃ_ʊ'
def test_separator_2(): backend = SegmentsBackend('cree') text = ['achi acho'] sep = Separator(word='_', phone=' ') assert backend.phonemize(text, separator=sep) == [u'ʌ tʃ ɪ _ʌ tʃ ʊ _'] assert backend.phonemize(text, separator=sep, strip=True) \ == [u'ʌ tʃ ɪ_ʌ tʃ ʊ']
def test_separator_4(): backend = SegmentsBackend('cree') text = 'achi acho' # TODO bug when sep.phone == ' ' with no sep.word sep = separator.Separator(phone=' ', word='') assert backend.phonemize(text, separator=sep) == u'ʌ tʃ ɪ ʌ tʃ ʊ ' assert backend.phonemize(text, separator=sep, strip=True) \ == u'ʌ tʃ ɪʌ tʃ ʊ'
def test_multiline(): backend = SegmentsBackend('cree') assert backend.language == 'cree' assert backend.phonemize(['a']) == [u'ʌ '] assert backend.phonemize(['aa']) == [u'ʌʌ '] assert backend.phonemize(['a\n']) == [u'ʌ '] assert backend.phonemize(['a\na']) == [u'ʌ ʌ '] assert backend.phonemize(['a\na\n']) == [u'ʌ ʌ '] assert backend.phonemize(['a', 'a']) == [u'ʌ ', 'ʌ '] assert backend.phonemize(['a\n', 'a\n']) == [u'ʌ ', 'ʌ ']
def test_bad_morpheme(): backend = SegmentsBackend('cree') with pytest.raises(ValueError): backend.phonemize('A')
def recognize(self, wav=None): if not self.eng.find("fest") == -1: # ======= festival english us only ===================================== from phonemizer.backend import FestivalBackend out1 = FestivalBackend( 'en-us', preserve_punctuation=False).phonemize(self.text, strip=True) elif not self.eng.find("esp") == -1: # ======= espeak ======================================================= from phonemizer.backend import EspeakBackend if not self.lan.find("en") == -1: backend = EspeakBackend('en-us') elif not self.lan.find("fr") == -1: backend = EspeakBackend('fr-fr') elif not self.lan.find("de") == -1 or not self.lan.find( "ger") == -1: backend = EspeakBackend('de-de') elif not self.lan.find("ita") == -1: backend = EspeakBackend('it-it') elif not self.lan.find("esp") == -1 or not self.lan.find( "spa") == -1: backend = EspeakBackend('es-es') else: print("Invalid Language specified") exit(1) sep = separator.Separator(word=';eword ', syllable=None, phone=' ') out1 = backend.phonemize(self.text, sep, False) elif not self.eng.find("mbr") == -1: # ====== mbrola ======================================================== from phonemizer.backend import EspeakBackend, EspeakMbrolaBackend if EspeakMbrolaBackend.is_available(): if not self.lan.find("en") == -1: EspeakMbrolaBackend('mb-en1') elif not self.lan.find("fr") == -1: EspeakMbrolaBackend('mb-fr2') elif not self.lan.find("de") == -1 or not self.lan.find( "ger") == -1: EspeakMbrolaBackend('mb-de1') elif not self.lan.find("ita") == -1: EspeakMbrolaBackend('mb-es1') elif not self.lan.find("esp") == -1 or not self.lan.find( "spa") == -1: EspeakMbrolaBackend('mb-it3') else: print("Invalid Language specified") exit(1) sep = separator.Separator(word=';eword ', syllable=None, phone=' ') out1 = backend.phonemize(self.text, sep, False) elif not self.eng.find("seg") == -1: # ===== segment ======================================================== from phonemizer.backend import SegmentsBackend if not self.lan.find("ja") == -1: backend = SegmentsBackend('japanese') else: print("Invalid Language specified") exit(1) sep = separator.Separator(word=';eword ', syllable=None, phone=' ') out1 = backend.phonemize(self.text, sep, False) else: print("Invalid Language specified") exit(1) print(out1) # return the result string to the speach engine