Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_punctuation(text, strip, sep):
if sep == separator.Separator():
expected = 'ɐ kɑːmə ɐ pɔɪnt' if strip else 'ɐ kɑːmə ɐ pɔɪnt '
else:
expected = (
'ɐ_k ɑː m ə_ɐ_p ɔɪ n t' if strip else 'ɐ _k ɑː m ə _ɐ _p ɔɪ n t _')
output = EspeakBackend('en-us').phonemize(text, strip=strip, separator=sep)
assert expected == output
backend = EspeakBackend('fr-fr', language_switch='remove-flags')
out = backend._phonemize_aux(text, separator.Separator(), True)
assert out == [
'ʒɛm lɑ̃ɡlɛ',
'ʒɛm lə- fʊtbɔːl',
'fʊtbɔːl',
'syʁtu lə- ɹiəl madʁid',
'nytiliz pa ɡuːɡəl']
backend = EspeakBackend('fr-fr', language_switch='remove-utterance')
out = backend._phonemize_aux(text, separator.Separator(), True)
assert out == ['ʒɛm lɑ̃ɡlɛ']
with pytest.raises(RuntimeError):
backend = EspeakBackend('fr-fr', language_switch='foo')
def test_phone_separator(text, expected):
sep = separator.Separator(phone='_')
backend = EspeakBackend('en-us')
output = backend.phonemize(text, separator=sep, strip=True)
assert output == expected
def test_versions(version):
expected = '1.49.2' if 'NG' in version else '1.48.03'
version_re = EspeakBackend.espeak_version_re
assert re.match(version_re, version).group(1) == expected
def test_french():
backend = EspeakBackend('fr-fr')
text = u'bonjour le monde'
sep = separator.Separator(word=';eword ', syllable=None, phone=' ')
expected = [u'b ɔ̃ ʒ u ʁ ;eword l ə- ;eword m ɔ̃ d ;eword ']
out = backend._phonemize_aux(text, sep, False)
assert out == expected
def test_phone_separator_simple():
text = 'The lion and the tiger ran'
sep = separator.Separator(phone='_')
backend = EspeakBackend('en-us')
output = backend.phonemize(text, separator=sep, strip=True)
expected = 'ð_ə l_aɪə_n æ_n_d ð_ə t_aɪ_ɡ_ɚ ɹ_æ_n'
assert expected == output
output = backend.phonemize(text, separator=sep, strip=False)
expected = 'ð_ə_ l_aɪə_n_ æ_n_d_ ð_ə_ t_aɪ_ɡ_ɚ_ ɹ_æ_n_ '
assert expected == output