Ejemplo n.º 1
0
def _test_pickle(voice):
    # the wrapper is pickled when using espeak backend on multiple jobs
    wrapper = EspeakWrapper()
    wrapper.set_voice(voice)

    dump = pickle.dumps(wrapper)
    wrapper2 = pickle.loads(dump)

    assert wrapper.version == wrapper2.version
    assert wrapper.library_path == wrapper2.library_path
    assert wrapper.data_path == wrapper2.data_path
    assert wrapper.voice == wrapper2.voice
Ejemplo n.º 2
0
    def set_library(cls, library):
        """Sets the espeak backend to use `library`

        If this is not set, the backend uses the default espeak shared library
        from the system installation.

        Parameters
        ----------
        library (str or None) : the path to the espeak shared library to use as
            backend. Set `library` to None to restore the default.

        """
        EspeakWrapper.set_library(library)
Ejemplo n.º 3
0
 def supported_languages(cls):  # pragma: nocover
     """Returns the list of installed mbrola voices"""
     if cls._supported_languages is None:
         data_path = EspeakWrapper().data_path
         cls._supported_languages = {
             k: v for k, v in cls._all_supported_languages().items()
             if cls._is_language_installed(k, data_path)}
     return cls._supported_languages
Ejemplo n.º 4
0
    def version(cls):
        """Espeak version as a tuple (major, minor, patch)

        Raises
        ------
        RuntimeError if BaseEspeakBackend.is_available() is False or if the
            version cannot be extracted for some reason.

        """
        return EspeakWrapper().version
Ejemplo n.º 5
0
    def __init__(self,
                 language,
                 punctuation_marks=Punctuation.default_marks(),
                 preserve_punctuation=False,
                 logger=get_logger()):
        self._espeak = EspeakWrapper()
        logger.debug('loaded %s', self._espeak.library_path)

        super().__init__(language,
                         punctuation_marks=punctuation_marks,
                         preserve_punctuation=preserve_punctuation,
                         logger=logger)
Ejemplo n.º 6
0
def test_path_good():
    espeak = EspeakBackend.library()
    try:
        EspeakBackend.set_library(None)
        assert espeak == EspeakBackend.library()

        library = EspeakWrapper().library_path
        EspeakBackend.set_library(library)

        test_english()

    # restore the espeak path to default
    finally:
        EspeakBackend.set_library(None)
Ejemplo n.º 7
0
def test_twice():
    wrapper1 = EspeakWrapper()
    wrapper2 = EspeakWrapper()

    assert wrapper1.data_path == wrapper2.data_path
    assert wrapper1.version == wrapper2.version
    assert wrapper1.library_path == wrapper2.library_path

    wrapper1.set_voice('fr-fr')
    assert wrapper1.voice.language == 'fr-fr'
    wrapper2.set_voice('en-us')
    assert wrapper2.voice.language == 'en-us'
    assert wrapper1.voice.language == 'fr-fr'

    # pylint: disable=protected-access
    assert wrapper1._espeak._tempdir != wrapper2._espeak._tempdir
Ejemplo n.º 8
0
    def library(cls):
        """Returns the espeak library used as backend

        The following precedence rule applies for library lookup:

        1. As specified by BaseEspeakBackend.set_library()
        2. Or as specified by the environment variable
           PHONEMIZER_ESPEAK_LIBRARY
        3. Or the default espeak library found on the system

        Raises
        ------
        RuntimeError if the espeak library cannot be found or if the
            environment variable PHONEMIZER_ESPEAK_LIBRARY is set to a
            non-readable file

        """
        return EspeakWrapper.library()
Ejemplo n.º 9
0
 def _all_supported_languages(cls):
     # retrieve the mbrola voices. This voices must be installed separately.
     voices = EspeakWrapper().available_voices('mbrola')
     return {voice.identifier[3:]: voice.name for voice in voices}
Ejemplo n.º 10
0
 def is_available(cls):
     try:
         EspeakWrapper()
     except RuntimeError:  # pragma: nocover
         return False
     return True
Ejemplo n.º 11
0
 def supported_languages(cls):
     return {
         voice.language: voice.name
         for voice in EspeakWrapper().available_voices()
     }
Ejemplo n.º 12
0
def wrapper():
    return EspeakWrapper()
Ejemplo n.º 13
0
def test_deletion():
    # pylint: disable=protected-access
    wrapper = EspeakWrapper()
    path = pathlib.Path(wrapper._espeak._tempdir)
    del wrapper
    assert not path.exists()