How to use the phonemizer.logger.get_logger function in phonemizer

To help you get started, we’ve selected a few phonemizer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bootphon / phonemizer / test / test_main.py View on Github external
def test_logger():
    with pytest.raises(RuntimeError):
        logger.get_logger(verbosity=1)
github bootphon / phonemizer / phonemizer / backend / espeak.py View on Github external
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

        self.ipa = '--ipa=3'
        if self.is_espeak_ng():  # this is espeak-ng
            self.ipa = '-x --ipa'

        self._with_stress = with_stress
        if use_sampa is True:
github bootphon / phonemizer / phonemizer / main.py View on Github external
def main():
    """Phonemize a text from command-line arguments"""
    args = parse_args()

    if args.version:
        print(version.version())
        return

    # configure logging according to --verbose/--quiet options
    verbosity = 'normal'
    if args.verbose:
        verbosity = 'verbose'
    elif args.quiet:
        verbosity = 'quiet'
    log = logger.get_logger(verbosity=verbosity)

    # configure input as a readable stream
    streamin = args.input
    if isinstance(streamin, str):
        streamin = codecs.open(streamin, 'r', encoding='utf8')
    log.debug('reading from %s', streamin.name)

    # configure output as a writable stream
    streamout = args.output
    if isinstance(streamout, str):
        streamout = codecs.open(streamout, 'w', 'utf8')
    log.debug('writing to %s', streamout.name)

    # configure the separator for phonemes, syllables and words.
    sep = separator.Separator(
        phone=args.phone_separator,
github bootphon / phonemizer / phonemizer / backend / segments.py View on Github external
    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)
github bootphon / phonemizer / phonemizer / backend / festival.py View on Github external
    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))
github bootphon / phonemizer / phonemizer / phonemize.py View on Github external
def phonemize(text, language='en-us', backend='festival',
              separator=default_separator, strip=False,
              with_stress=False, use_sampa=False,
              language_switch='keep-flags',
              njobs=1, logger=get_logger()):
    """Multilingual text to phonemes converter

    Return a phonemized version of an input `text`, given its
    `language` and a phonemization `backend`.

    Parameters
    ----------
    text (str or list of str): The text to be phonemized. Any empty
       line will be ignored. If `text` is an str, it can be multiline
       (lines being separated by \n). If `text` is a list, each
       element is considered as a separated line. Each line is
       considered as a text utterance.

    language (str): The language code of the input text, must be
      supported by the backend. If `backend` is 'segments', the
      language can be a file with a grapheme to phoneme mapping.
github bootphon / phonemizer / phonemizer / backend / base.py View on Github external
    def __init__(self, language, logger=get_logger()):
        # ensure the backend is installed on the system
        if not self.is_available():
            raise RuntimeError(  # pragma: nocover
                '{} not installed on your system'.format(self.name()))

        self.logger = logger
        self.logger.info(
            'initializing backend %s-%s', self.name(), self.version())

        # ensure the backend support the requested language
        if not self.is_supported_language(language):
            raise RuntimeError(
                'language "{}" is not supported by the {} backend'
                .format(language, self.name()))
        self.language = language