How to use the phonemizer.separator.Separator function in phonemizer

To help you get started, we’ve selected a few phonemizer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bootphon / phonemizer / test / test_espeak.py View on Github external
def test_arabic():
    backend = EspeakBackend('ar')
    text = u'السلام عليكم'
    sep = separator.Separator()

    # Arabic seems to have changed starting at espeak-ng-1.49.3
    if tuple(EspeakBackend.version().split('.')) >= ('1', '49', '3'):
        expected = [u'ʔassalaːm ʕliːkm ']
    else:
        expected = [u'ʔassalaam ʕaliijkum ']
    out = backend._phonemize_aux(text, sep, False)
    assert out == expected
github bootphon / phonemizer / test / test_espeak.py View on Github external
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
github bootphon / phonemizer / test / test_separator.py View on Github external
def test_equal():
    assert Separator() == Separator()
    assert default_separator == Separator(phone='', syllable='', word=' ')
    assert Separator(word='  ') != default_separator
github bootphon / phonemizer / test / test_separator.py View on Github external
def test_same():
    with pytest.raises(ValueError):
        Separator(word=' ', phone=' ')
github bootphon / phonemizer / test / test_espeak.py View on Github external
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
github bootphon / phonemizer / test / test_separator.py View on Github external
def test_str():
    separator = Separator(word='w', syllable='s', phone='p')
    assert str(separator) == '(phone: "p", syllable: "s", word: "w")'
    assert str(default_separator) == '(phone: "", syllable: "", word: " ")'
github bootphon / phonemizer / test / test_separator.py View on Github external
def test_empty(val):
    s = Separator(val, val, val)
    assert s.phone == ''
    assert s.syllable == ''
    assert s.word == ''
github bootphon / phonemizer / phonemizer / main.py View on Github external
log = logger.get_logger(verbosity=verbosity)

    # configure input as a readable stream
    streamin = args.input
    if isinstance(streamin, str):
        streamin = codecs.open(streamin, 'r', encoding='utf8')
    log.debug('reading from %s', streamin.name)

    # configure output as a writable stream
    streamout = args.output
    if isinstance(streamout, str):
        streamout = codecs.open(streamout, 'w', 'utf8')
    log.debug('writing to %s', streamout.name)

    # configure the separator for phonemes, syllables and words.
    sep = separator.Separator(
        phone=args.phone_separator,
        syllable=args.syllable_separator,
        word=args.word_separator)
    log.debug('separator is %s', sep)

    # load the input text (python2 optionnally needs an extra decode)
    text = streamin.read()
    try:
        text = text.decode('utf8')
    except (AttributeError, UnicodeEncodeError):
        pass

    # phonemize the input text
    out = phonemize.phonemize(
        text,
        language=args.language,