Esempio n. 1
0
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:
        version += '\navailable backends: ' + ', '.join(available)
    if unavailable:  # pragma: nocover
        version += '\nuninstalled backends: ' + ', '.join(unavailable)

    return version
Esempio n. 2
0
def test_path_venv():
    try:
        os.environ['PHONEMIZER_FESTIVAL_EXECUTABLE'] = shutil.which('python')
        with pytest.raises(RuntimeError):
            FestivalBackend('en-us').phonemize(['hello'])
        with pytest.raises(RuntimeError):
            FestivalBackend.version()

        os.environ['PHONEMIZER_FESTIVAL_EXECUTABLE'] = __file__
        with pytest.raises(RuntimeError):
            FestivalBackend.version()

    finally:
        try:
            del os.environ['PHONEMIZER_FESTIVAL_EXECUTABLE']
        except KeyError:
            pass
Esempio n. 3
0
def test_path_bad():
    try:
        # corrupt the default espeak path, try to use python executable instead
        binary = shutil.which('python')
        FestivalBackend.set_executable(binary)

        with pytest.raises(RuntimeError):
            FestivalBackend('en-us').phonemize(['hello'])
        with pytest.raises(RuntimeError):
            FestivalBackend.version()

        with pytest.raises(RuntimeError):
            FestivalBackend.set_executable(__file__)

    # restore the festival path to default
    finally:
        FestivalBackend.set_executable(None)
Esempio n. 4
0
def test_path_venv():
    try:
        os.environ['PHONEMIZER_FESTIVAL_PATH'] = distutils.spawn.find_executable('python')
        with pytest.raises(RuntimeError):
            FestivalBackend('en-us').phonemize('hello')
        with pytest.raises(RuntimeError):
            FestivalBackend.version()

        os.environ['PHONEMIZER_FESTIVAL_PATH'] = __file__
        with pytest.raises(ValueError):
            FestivalBackend.version()

    finally:
        try:
            del os.environ['PHONEMIZER_FESTIVAL_PATH']
        except KeyError:
            pass
Esempio n. 5
0
def test_path_bad():
    try:
        # corrupt the default espeak path, try to use python executable instead
        binary = distutils.spawn.find_executable('python')
        FestivalBackend.set_festival_path(binary)

        with pytest.raises(RuntimeError):
            FestivalBackend('en-us').phonemize('hello')
        with pytest.raises(RuntimeError):
            FestivalBackend.version()

        with pytest.raises(ValueError):
            FestivalBackend.set_festival_path(__file__)

    # restore the festival path to default
    finally:
        FestivalBackend.set_festival_path(None)
Esempio n. 6
0
def version():
    """Return version information for front and backends"""
    version = ('phonemizer-' +
               pkg_resources.get_distribution('phonemizer').version)

    return version + '\navailable backends: ' + ', '.join(
        ('festival-' + FestivalBackend.version(),
         ('espeak-' + ('ng-' if EspeakBackend.is_espeak_ng() else '') +
          EspeakBackend.version()), 'segments-' + SegmentsBackend.version()))
Esempio n. 7
0
def version():
    """Return version information for front and backends"""
    version = ('phonemizer-'
               + pkg_resources.get_distribution('phonemizer').version)

    return version + '\navailable backends: ' + ', '.join(
        ('festival-' + FestivalBackend.version(),
         ('espeak-' + ('ng-' if EspeakBackend.is_espeak_ng() else '')
          + EspeakBackend.version()),
         'segments-' + SegmentsBackend.version()))
Esempio n. 8
0
# pylint: disable=missing-docstring

import pytest

from phonemizer.backend import EspeakBackend, FestivalBackend, SegmentsBackend
from phonemizer.punctuation import Punctuation
from phonemizer.phonemize import phonemize

# True if we are using espeak>=1.50
ESPEAK_150 = (EspeakBackend.version() >= (1, 50))

# True if we are using espeak>=1.49.3
ESPEAK_143 = (EspeakBackend.version() >= (1, 49, 3))

# True if we are using festival>=2.5
FESTIVAL_25 = (FestivalBackend.version() >= (2, 5))


@pytest.mark.parametrize('inp, out', [('a, b,c.', 'a b c'),
                                      ('abc de', 'abc de'),
                                      ('!d.d. dd??  d!', 'd d dd d')])
def test_remove(inp, out):
    assert Punctuation().remove(inp) == out


@pytest.mark.parametrize(
    'inp', [['.a.b.c.'], ['a, a?', 'b, b'], ['a, a?', 'b, b', '!'],
            ['a, a?', '!?', 'b, b'], ['!?', 'a, a?', 'b, b'], ['a, a, a'],
            ['a, a?', 'aaa bb', '.bb, b', 'c', '!d.d. dd??  d!'],
            ['Truly replied, "Yes".'], ['hi; ho,"'], ["!?"], ["!'"]])
def test_preserve(inp):
Esempio n. 9
0
import shutil

import pytest

from phonemizer.separator import Separator
from phonemizer.backend import FestivalBackend


def _test(text, separator=Separator(word=' ', syllable='|', phone='-')):
    backend = FestivalBackend('en-us')
    # pylint: disable=protected-access
    return backend._phonemize_aux(text, 0, separator, True)


@pytest.mark.skipif(
    FestivalBackend.version() <= (2, 1),
    reason='festival-2.1 gives different results than further versions '
    'for syllable boundaries')
def test_hello():
    assert _test(['hello world']) == ['hh-ax|l-ow w-er-l-d']
    assert _test(['hello', 'world']) == ['hh-ax|l-ow', 'w-er-l-d']


@pytest.mark.parametrize('text', ['', ' ', '  ', '(', '()', '"', "'"])
def test_bad_input(text):
    assert _test(text) == []


def test_quote():
    assert _test(["it's"]) == ['ih-t-s']
    assert _test(["its"]) == ['ih-t-s']
Esempio n. 10
0
import distutils.spawn
import os
import pytest
from phonemizer import separator
from phonemizer.backend import FestivalBackend


def _test(text, separator=separator.Separator(
        word=' ', syllable='|', phone='-')):
    backend = FestivalBackend('en-us')
    return backend._phonemize_aux(text, separator, True)


@pytest.mark.skipif(
    '2.1' in FestivalBackend.version(),
    reason='festival-2.1 gives different results than further versions '
    'for syllable boundaries')
def test_hello():
    assert _test('hello world') == ['hh-ax|l-ow w-er-l-d']
    assert _test('hello\nworld') == ['hh-ax|l-ow', 'w-er-l-d']
    assert _test('hello\nworld\n') == ['hh-ax|l-ow', 'w-er-l-d']


@pytest.mark.parametrize('text', ['', ' ', '  ', '(', '()', '"', "'"])
def test_bad_input(text):
    assert _test(text) == []


def test_quote():
    assert _test("here a 'quote") == ['hh-ih-r ax k-w-ow-t']
Esempio n. 11
0
import pytest

from phonemizer.backend import EspeakBackend, FestivalBackend, SegmentsBackend
from phonemizer.punctuation import Punctuation
from phonemizer.phonemize import phonemize


# True if we are using espeak>=1.49.3
ESPEAK_143 = (EspeakBackend.version(as_tuple=True) >= (1, 49, 3))

# True if we are using espeak>=1.50
ESPEAK_150 = (EspeakBackend.version(as_tuple=True) >= (1, 50))

# True if we are using festival>=2.5
FESTIVAL_25 = (FestivalBackend.version(as_tuple=True) >= (2, 5))


@pytest.mark.parametrize(
    'inp, out', [
        ('a, b,c.', 'a b c'),
        ('abc de', 'abc de'),
        ('!d.d. dd??  d!', 'd d dd d')])
def test_remove(inp, out):
    assert Punctuation().remove(inp) == out


@pytest.mark.parametrize(
    'inp', [
        ['.a.b.c.'],
        ['a, a?', 'b, b'],