Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import re
import shlex
import subprocess
import tempfile
from phonemizer.backend.base import BaseBackend
from phonemizer.logger import get_logger
# a regular expression to find language switching flags in espeak output,
# Switches have the following form (here a switch from English to French):
# "something (fr) quelque chose (en) another thing".
_ESPEAK_FLAGS_RE = re.compile(r'\(.+?\)')
class EspeakBackend(BaseBackend):
"""Espeak backend for the phonemizer"""
espeak_version_re = r'.*: ([0-9]+\.[0-9]+\.[0-9]+)'
def __init__(self, language, use_sampa=False,
language_switch='keep-flags', with_stress=False,
logger=get_logger()):
super(self.__class__, self).__init__(language, logger=logger)
# adapt some command line option to the espeak version (for
# phoneme separation and IPA output)
version = self.version()
self.sep = '--sep=_'
if version == '1.48.03' or int(version.split('.')[1]) <= 47:
self.sep = '' # pragma: nocover
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with phonemizer. If not, see .
"""Segments backend for the phonemizer"""
import codecs
import os
import pkg_resources
import segments
from phonemizer.backend.base import BaseBackend
from phonemizer.logger import get_logger
class SegmentsBackend(BaseBackend):
"""Segments backends for the phonemizer
The phonemize method will raise a ValueError when parsing an
unknown morpheme.
"""
def __init__(self, language, logger=get_logger()):
self.logger = logger
self.logger.info(
'initializing backend %s-%s', self.name(), self.version())
profile = self._load_g2p_profile(language)
self.tokenizer = segments.Tokenizer(profile=profile)
@staticmethod
def name():
import distutils
import os
import pkg_resources
import re
import shlex
import subprocess
import tempfile
import phonemizer.lispy as lispy
from phonemizer.backend.base import BaseBackend
from phonemizer.logger import get_logger
class FestivalBackend(BaseBackend):
def __init__(self, language, logger=get_logger()):
super(self.__class__, self).__init__(language, logger=logger)
self.script = pkg_resources.resource_filename(
pkg_resources.Requirement.parse('phonemizer'),
'phonemizer/share/phonemize.scm')
self.logger.info('loaded {}'.format(self.script))
@staticmethod
def name():
return 'festival'
@staticmethod
def is_available():
return distutils.spawn.find_executable('festival')