本文整理汇总了Python中aeneas.logger.Logger类的典型用法代码示例。如果您正苦于以下问题:Python Logger类的具体用法?Python Logger怎么用?Python Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_log
def test_log(self):
logger = Logger(tee=False, indentation=4)
logger.log(u"Message 1", Logger.DEBUG)
logger.log(u"Message 2", Logger.INFO)
logger.log(u"Message 3", Logger.WARNING)
logger.log(u"Message 4", Logger.CRITICAL)
self.assertEqual(len(logger), 4)
示例2: test_tag
def test_tag(self):
logger = Logger(tee=False, indentation=4)
logger.log(u"Message 1", Logger.DEBUG, tag=u"TEST")
logger.log(u"Message 2", Logger.DEBUG)
logger.log(u"Message 3", Logger.DEBUG, tag=u"TEST")
logger.log(u"Message 4", Logger.DEBUG)
strings = logger.pretty_print(as_list=True)
self.assertEqual(strings[0].find(u"TEST") > -1, True)
self.assertEqual(strings[1].find(u"TEST") > -1, False)
self.assertEqual(strings[2].find(u"TEST") > -1, True)
self.assertEqual(strings[3].find(u"TEST") > -1, False)
示例3: test_tag
def test_tag(self):
logger = Logger(tee=False, indentation=4)
logger.log("Message 1", Logger.DEBUG, tag="TEST")
logger.log("Message 2", Logger.DEBUG)
logger.log("Message 3", Logger.DEBUG, tag="TEST")
logger.log("Message 4", Logger.DEBUG)
strings = logger.to_list_of_strings()
self.assertEqual(strings[0].find("TEST") > -1, True)
self.assertEqual(strings[1].find("TEST") > -1, False)
self.assertEqual(strings[2].find("TEST") > -1, True)
self.assertEqual(strings[3].find("TEST") > -1, False)
示例4: __init__
def __init__(self, job=None, logger=None):
self.job = job
self.working_directory = None
self.tmp_directory = None
self.logger = logger
if self.logger == None:
self.logger = Logger()
示例5: __init__
def __init__(self, file_path, container_format=None, logger=None):
self.file_path = file_path
self.container_format = container_format
self.actual_container = None
self.logger = logger
if self.logger is None:
self.logger = Logger()
self._log("Setting actual Container object")
self._set_actual_container()
示例6: __init__
def __init__(self, file_path, logger=None):
self.logger = logger
if self.logger == None:
self.logger = Logger()
self.file_path = file_path
self.file_size = None
self.audio_length = None
self.audio_format = None
self.audio_sample_rate = None
self.audio_channels = None
self._read_properties()
示例7: __init__
def __init__(self, file_path, logger=None):
self.logger = logger
if self.logger is None:
self.logger = Logger()
self.file_path = file_path
self.file_size = None
self.audio_data = None
self.audio_length = None
self.audio_format = None
self.audio_sample_rate = None
self.audio_channels = None
self.audio_mfcc = None
示例8: __init__
def __init__(
self,
audio_file,
text_file,
frame_rate=gc.MFCC_FRAME_RATE,
logger=None
):
self.logger = logger
if self.logger is None:
self.logger = Logger()
self.audio_file = audio_file
self.text_file = text_file
self.frame_rate = frame_rate
self.audio_speech = None
示例9: __init__
def __init__(
self,
file_path=None,
file_format=None,
parameters=None,
logger=None
):
self.file_path = file_path
self.file_format = file_format
self.parameters = parameters
self.fragments = []
self.logger = Logger()
if logger is not None:
self.logger = logger
if (self.file_path is not None) and (self.file_format is not None):
self._read_from_file()
示例10: __init__
def __init__(
self,
algorithm,
text_map,
speech,
nonspeech,
value=None,
logger=None
):
self.algorithm = algorithm
self.text_map = copy.deepcopy(text_map)
self.speech = speech
self.nonspeech = nonspeech
self.value = value
self.logger = logger
self.max_rate = self.DEFAULT_MAX_RATE
if self.logger is None:
self.logger = Logger()
示例11: __init__
def __init__(
self,
wave_path_1,
wave_path_2,
frame_rate=gc.ALIGNER_FRAME_RATE,
margin=gc.ALIGNER_MARGIN,
algorithm=DTWAlgorithm.STRIPE,
logger=None
):
self.logger = logger
if self.logger == None:
self.logger = Logger()
self.wave_path_1 = wave_path_1
self.wave_path_2 = wave_path_2
self.frame_rate = frame_rate
self.margin = margin
self.algorithm = algorithm
self.wave_mfcc_1 = None
self.wave_mfcc_2 = None
self.wave_len_1 = None
self.wave_len_2 = None
self.computed_path = None
示例12: __init__
def __init__(
self,
real_wave_path,
synt_wave_path,
frame_rate=gc.MFCC_FRAME_RATE,
margin=gc.ALIGNER_MARGIN,
algorithm=DTWAlgorithm.STRIPE,
logger=None
):
self.logger = logger
if self.logger is None:
self.logger = Logger()
self.real_wave_path = real_wave_path
self.synt_wave_path = synt_wave_path
self.frame_rate = frame_rate
self.margin = margin
self.algorithm = algorithm
self.real_wave_full_mfcc = None
self.synt_wave_full_mfcc = None
self.real_wave_length = None
self.synt_wave_length = None
self.computed_path = None
示例13: __init__
def __init__(
self,
wave_path=None,
frame_rate=gc.MFCC_FRAME_RATE,
energy_threshold=gc.VAD_LOG_ENERGY_THRESHOLD,
min_nonspeech_length=gc.VAD_MIN_NONSPEECH_LENGTH,
extend_after=gc.VAD_EXTEND_SPEECH_INTERVAL_AFTER,
extend_before=gc.VAD_EXTEND_SPEECH_INTERVAL_BEFORE,
logger=None
):
self.logger = logger
if self.logger is None:
self.logger = Logger()
self.wave_path = wave_path
self.frame_rate = frame_rate
self.energy_threshold = energy_threshold
self.min_nonspeech_length = min_nonspeech_length
self.extend_after = extend_after
self.extend_before = extend_before
self.wave_mfcc = None
self.wave_len = None
self.speech = None
self.nonspeech = None
示例14: ESPEAKWrapper
class ESPEAKWrapper(object):
"""
Wrapper around ``espeak`` to synthesize text into a ``wav`` audio file.
It will perform a call like ::
$ espeak -v language_code -w /tmp/output_file.wav < text
:param logger: the logger object
:type logger: :class:`aeneas.logger.Logger`
"""
TAG = "ESPEAKWrapper"
def __init__(self, logger=None):
self.logger = logger
if self.logger is None:
self.logger = Logger()
def _log(self, message, severity=Logger.DEBUG):
""" Log """
self.logger.log(message, severity, self.TAG)
def _replace_language(self, language):
"""
Mock support for a given language by
synthesizing using a similar language.
:param language: the requested language
:type language: string (from :class:`aeneas.language.Language` enumeration)
:rtype: string (from :class:`aeneas.language.Language` enumeration)
"""
if language == Language.UK:
self._log(["Replaced '%s' with '%s'", Language.UK, Language.RU])
return Language.RU
return language
def synthesize(self, text, language, output_file_path):
"""
Create a ``wav`` audio file containing the synthesized text.
The ``text`` must be a unicode string encodable with UTF-8,
otherwise ``espeak`` might fail.
Return the duration of the synthesized audio file, in seconds.
:param text: the text to synthesize
:type text: unicode
:param language: the language to use
:type language: string (from :class:`aeneas.language.Language` enumeration)
:param output_file_path: the path of the output audio file
:type output_file_path: string
:rtype: float
"""
self._log(["Synthesizing text: '%s'", text])
self._log(["Synthesizing language: '%s'", language])
self._log(["Synthesizing to file: '%s'", output_file_path])
# return 0 if no text is given
if (text is None) or (len(text) == 0):
self._log("Text is None or it has zero length")
return 0
# return 0 if the requested language is not listed in language.py
# NOTE disabling this check to allow testing new languages
# TODO put it back, add an option in gc to allow unlisted languages
#if language not in Language.ALLOWED_VALUES:
# self._log(["Language %s is not allowed", language])
# return 0
# replace language
language = self._replace_language(language)
self._log(["Using language: '%s'", language])
# call espeak
arguments = []
arguments += [gc.ESPEAK_PATH]
arguments += ["-v", language]
arguments += ["-w", output_file_path]
self._log(["Calling with arguments '%s'", " ".join(arguments)])
self._log(["Calling with text '%s'", text])
proc = subprocess.Popen(
arguments,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
proc.communicate(input=text.encode('utf-8'))
proc.stdout.close()
proc.stdin.close()
proc.stderr.close()
self._log("Call completed")
# check if the output file exists
if not os.path.exists(output_file_path):
self._log(["Output file '%s' cannot be read", output_file_path], Logger.CRITICAL)
raise OSError("Output file cannot be read")
# return the duration of the output file
self._log(["Calling wavread to analyze file '%s'", output_file_path])
#.........这里部分代码省略.........
示例15: TextFile
class TextFile(object):
"""
A list of text fragments.
:param logger: the logger object
:type logger: :class:`aeneas.logger.Logger`
"""
TAG = "TextFile"
def __init__(
self,
file_path=None,
file_format=None,
parameters=None,
logger=None
):
self.file_path = file_path
self.file_format = file_format
self.parameters = parameters
self.fragments = []
self.logger = Logger()
if logger is not None:
self.logger = logger
if (self.file_path is not None) and (self.file_format is not None):
self._read_from_file()
def __len__(self):
return len(self.fragments)
def __str__(self):
return "\n".join([str(f) for f in self.fragments])
def _log(self, message, severity=Logger.DEBUG):
""" Log """
self.logger.log(message, severity, self.TAG)
@property
def characters(self):
"""
The number of characters in this text.
:rtype: int
"""
chars = 0
for fragment in self.fragments:
chars += fragment.characters
return chars
@property
def fragments(self):
"""
The current list of text fragments.
:rtype: list of :class:`aeneas.textfile.TextFragment`
"""
return self.__fragments
@fragments.setter
def fragments(self, fragments):
self.__fragments = fragments
def append_fragment(self, fragment):
"""
Append the given text fragment to the current list.
:param fragment: the text fragment to be appended
:type fragment: :class:`aeneas.textfile.TextFragment`
"""
self.fragments.append(fragment)
def get_slice(self, start=None, end=None):
"""
Return a new list of text fragments,
indexed from start (included) to end (excluded).
:param start: the start index
:type start: int
:param end: the end index
:type end: int
:rtype: :class:`aeneas.textfile.TextFile`
"""
if start is not None:
start = min(max(0, start), len(self) - 1)
else:
start = 0
if end is not None:
end = min(max(0, end), len(self))
end = max(end, start + 1)
else:
end = len(self)
new_text = TextFile()
for fragment in self.fragments[start:end]:
new_text.append_fragment(fragment)
return new_text
def set_language(self, language):
"""
Set the given language for all the text fragments.
#.........这里部分代码省略.........