Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _test(text, separator=separator.Separator(
word=' ', syllable='|', phone='-')):
backend = FestivalBackend('en-us')
return backend._phonemize_aux(text, separator, True)
# language_switch option only valid for espeak
if language_switch != 'keep-flags' and backend != 'espeak':
raise RuntimeError(
'the "language_switch" option is available for espeak backend '
'only, but you are using {} backend'.format(backend))
# python2 needs additional utf8 encoding
if sys.version_info[0] == 2: # pragma: nocover
logger.warning(
'Your are using python2 but unsupported by the phonemizer, '
'please update to python3')
# instanciate the requested backend for the given language (raises
# a RuntimeError if the language is not supported).
backends = {b.name(): b for b in (
EspeakBackend, FestivalBackend, SegmentsBackend)}
if backend == 'espeak':
phonemizer = backends[backend](
language,
with_stress=with_stress,
use_sampa=use_sampa,
language_switch=language_switch,
logger=logger)
else:
phonemizer = backends[backend](language, logger=logger)
# phonemize the input text with the backend
return phonemizer.phonemize(
text, separator=separator, strip=strip, njobs=njobs)
# 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