Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
word = cls._postprocess_word(word, separator, strip)
if word != '':
out.append(word)
out = sep.join(out)
return out if strip else out + sep
@classmethod
def _postprocess(cls, tree, separator, strip):
"""Conversion from festival syllable tree to desired format"""
return [cls._postprocess_line(line, separator, strip)
for line in tree.split('\n')
if line not in ['', '(nil nil nil)']]
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=logging.getLogger()):
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():
out = list(itertools.chain(*out))
# restore the log as it was before parallel processing
self.logger = log_storage
# output the result formatted as a string or a list of strings
# according to type(text)
return (self._list2str(out)
if isinstance(text, six.string_types) else out)
@abc.abstractmethod
def _phonemize_aux(self, text, separator, strip):
pass
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, logger=logging.getLogger()):
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 = ''
self.ipa = '--ipa=3'
# remove the stresses on phonemes
w = word.strip().replace(u"ˈ", u'').replace(
u'ˌ', u'').replace(u"'", u'')
if not strip:
w += '_'
w = w.replace('_', separator.phone)
out_line += w + separator.word
if strip:
out_line = out_line[:-len(separator.word)]
output.append(out_line)
return output
class FestivalBackend(BaseBackend):
def __init__(self, language, logger=logging.getLogger()):
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')