How to use the phonemizer.backend.EspeakBackend.is_espeak_ng 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_main.py View on Github external
def test_readme():
    _test(u'hello world', u'həloʊ wɜːld ')
    _test(u'hello world', u'həloʊ wɜːld ', '--verbose')
    _test(u'hello world', u'həloʊ wɜːld ', '--quiet')

    if backend.EspeakBackend.is_espeak_ng():
        _test(u'hello world', u'h@loU w3:ld ', '--sampa')
    else:  # sampa only supported by espeak-ng
        with pytest.raises(SystemExit):
            _test(u'hello world', u'h@loU w3:ld ', '--sampa')

    _test(u'hello world', u'hhaxlow werld', '-b festival --strip')
    _test(u'hello world', u'həloʊ wɜːld ', '-l en-us')
    _test(u'bonjour le monde', u'bɔ̃ʒuʁ lə- mɔ̃d ', '-l fr-fr')
    _test(u'bonjour le monde', u'b ɔ̃ ʒ u ʁ ;eword l ə- ;eword m ɔ̃ d ;eword ',
          '-l fr-fr -p " " -w ";eword "')
github bootphon / phonemizer / test / test_espeak.py View on Github external
    not EspeakBackend.is_espeak_ng(),
    reason='Arabic is only supported by espeak-ng')
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_phonemize.py View on Github external
def test_espeak(njobs):
    text = ['one two', 'three', 'four five']

    out = phonemize(
        text, language='en-us', backend='espeak',
        strip=True, njobs=njobs)
    assert out == ['wʌn tuː', 'θɹiː', 'foːɹ faɪv']

    if EspeakBackend.is_espeak_ng():
        out = phonemize(
            text, language='en-us', backend='espeak', use_sampa=True,
            strip=True, njobs=njobs)
        assert out == ['wVn tu:', 'Tri:', 'fo@ faIv']

    out = phonemize(
        text, language='en-us', backend='espeak',
        strip=False, njobs=njobs)
    assert out == ['wʌn tuː ', 'θɹiː ', 'foːɹ faɪv ']

    out = phonemize(
        ' '.join(text), language='en-us', backend='espeak',
        strip=True, njobs=njobs)
    assert out == ' '.join(['wʌn tuː', 'θɹiː', 'foːɹ faɪv'])

    out = phonemize(
github bootphon / phonemizer / phonemizer / version.py View on Github external
def version():
    """Return version information for front and backends"""
    # version of the phonemizer
    version = (
        'phonemizer-' + pkg_resources.get_distribution('phonemizer').version)

    # for each backend, check if it is available or not. If so get its version
    available = []
    unavailable = []

    if EspeakBackend.is_available():
        available.append(
            'espeak-' + ('ng-' if EspeakBackend.is_espeak_ng() else '')
            + EspeakBackend.version())
    else:  # pragma: nocover
        unavailable.append('espeak')

    if FestivalBackend.is_available():
        available.append('festival-' + FestivalBackend.version())
    else:  # pragma: nocover
        unavailable.append('festival')

    if SegmentsBackend.is_available():
        available.append('segments-' + SegmentsBackend.version())
    else:  # pragma: nocover
        unavailable.append('segments')

    # resumes the backends status in the final version string
    if available:
github bootphon / phonemizer / phonemizer / phonemize.py View on Github external
If the `backend` is not valid or is valid but not installed, if the
      `language` is not supported by the `backend`, if `use_sampa`,
      `with_stress` or `language_switch` are used but the backend is not
      'espeak-ng'.

    """
    # ensure the backend is either espeak, festival or segments
    if backend not in ('espeak', 'festival', 'segments'):
        raise RuntimeError(
            '{} is not a supported backend, choose in {}.'
            .format(backend, ', '.join(('espeak', 'festival', 'segments'))))

    # ensure the phonetic alphabet is valid
    if use_sampa is True:
        if backend == 'espeak' and not EspeakBackend.is_espeak_ng():
            raise RuntimeError(  # pragma: nocover
                'sampa alphabet is not supported by espeak, '
                'please install espeak-ng')
        if backend != 'espeak':
            raise RuntimeError(
                'sampa alphabet is only supported by espeak backend')

    # with_stress option only valid for espeak
    if with_stress and backend != 'espeak':
        raise RuntimeError(
            'the "with_stress" option is available for espeak backend only, '
            'but you are using {} backend'.format(backend))

    # language_switch option only valid for espeak
    if language_switch != 'keep-flags' and backend != 'espeak':
        raise RuntimeError(