예제 #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
예제 #2
0
def test_path_venv():
    try:
        os.environ['PHONEMIZER_ESPEAK_LIBRARY'] = (shutil.which('python'))
        with pytest.raises(RuntimeError):
            EspeakBackend('en-us').phonemize(['hello'])
        with pytest.raises(RuntimeError):
            EspeakBackend.version()

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

    finally:
        try:
            del os.environ['PHONEMIZER_ESPEAK_LIBRARY']
        except KeyError:
            pass
예제 #3
0
def test_path_venv():
    try:
        os.environ['PHONEMIZER_ESPEAK_PATH'] = (
            distutils.spawn.find_executable('python'))
        with pytest.raises(RuntimeError):
            EspeakBackend('en-us').phonemize('hello')
        with pytest.raises(RuntimeError):
            EspeakBackend.version()

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

    finally:
        try:
            del os.environ['PHONEMIZER_ESPEAK_PATH']
        except KeyError:
            pass
예제 #4
0
def test_path_bad():
    espeak = EspeakBackend.espeak_path()
    try:
        # corrupt the default espeak path, try to use python executable instead
        binary = distutils.spawn.find_executable('python')
        EspeakBackend.set_espeak_path(binary)

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

        with pytest.raises(ValueError):
            EspeakBackend.set_espeak_path(__file__)

    # restore the espeak path to default
    finally:
        EspeakBackend.set_espeak_path(espeak)
예제 #5
0
파일: main.py 프로젝트: tronin/phonemizer
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()))
예제 #6
0
def test_path_bad():
    try:
        # corrupt the default espeak path, try to use python executable instead
        binary = shutil.which('python')
        EspeakBackend.set_library(binary)

        with pytest.raises(RuntimeError):
            EspeakBackend('en-us')
        with pytest.raises(RuntimeError):
            EspeakBackend.version()

        EspeakBackend.set_library(__file__)
        with pytest.raises(RuntimeError):
            EspeakBackend('en-us')

    # restore the espeak path to default
    finally:
        EspeakBackend.set_library(None)
예제 #7
0
파일: main.py 프로젝트: bootphon/phonemizer
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()))
예제 #8
0
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
예제 #9
0
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
예제 #10
0
def test_arabic():
    backend = EspeakBackend('ar')
    text = ['السلام عليكم']
    sep = Separator()

    # Arabic seems to have changed starting at espeak-ng-1.49.3
    if EspeakBackend.version() >= (1, 49, 3):
        expected = ['ʔassalaːm ʕliːkm ']
    else:
        expected = ['ʔassalaam ʕaliijkum ']
    out = backend.phonemize(text, sep, False)
    assert out == expected
예제 #11
0
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with phonemizer. If not, see <http://www.gnu.org/licenses/>.
"""Test of the punctuation processing"""

# 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

예제 #12
0
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with phonemizer. If not, see <http://www.gnu.org/licenses/>.
"""Test of the punctuation processing"""

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(as_tuple=True) >= (1, 50))


@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):
예제 #13
0
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with phonemizer. If not, see <http://www.gnu.org/licenses/>.
"""Test of the punctuation processing"""

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))


@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):