当前位置: 首页>>代码示例>>Python>>正文


Python Logger.log方法代码示例

本文整理汇总了Python中aeneas.logger.Logger.log方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.log方法的具体用法?Python Logger.log怎么用?Python Logger.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aeneas.logger.Logger的用法示例。


在下文中一共展示了Logger.log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_log

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
 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)
开发者ID:ptrwtts,项目名称:aeneas,代码行数:9,代码来源:test_logger.py

示例2: test_change_indentation

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
 def test_change_indentation(self):
     logger = Logger(tee=False, indentation=4)
     self.assertEqual(logger.indentation, 4)
     logger.log(u"Message 1", Logger.DEBUG)
     logger.log(u"Message 2", Logger.INFO)
     logger.indentation = 2
     self.assertEqual(logger.indentation, 2)
     logger.log(u"Message 3", Logger.WARNING)
     logger.log(u"Message 4", Logger.CRITICAL)
     logger.indentation = 0
     self.assertEqual(logger.indentation, 0)
开发者ID:ptrwtts,项目名称:aeneas,代码行数:13,代码来源:test_logger.py

示例3: test_tag

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
 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)
开发者ID:ptrwtts,项目名称:aeneas,代码行数:13,代码来源:test_logger.py

示例4: test_tag

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
 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)
开发者ID:fduch2k,项目名称:aeneas,代码行数:13,代码来源:test_logger.py

示例5: Synthesizer

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class Synthesizer(object):
    """
    A class to synthesize text fragments into
    a single ``wav`` file,
    along with the corresponding time anchors.

    :param logger: the logger object
    :type  logger: :class:`aeneas.logger.Logger`
    """

    TAG = "Synthesizer"

    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 synthesize(self, text_file, audio_file_path, quit_after=None, backwards=False):
        """
        Synthesize the text contained in the given fragment list
        into a ``wav`` file.

        :param text_file: the text file to be synthesized
        :type  text_file: :class:`aeneas.textfile.TextFile`
        :param audio_file_path: the path to the output audio file
        :type  audio_file_path: string (path)
        :param quit_after: stop synthesizing as soon as
                           reaching this many seconds
        :type  quit_after: float
        :param backwards: synthesizing from the end of the text file
        :type  backwards: bool
        """

        # time anchors
        anchors = []

        # initialize time
        current_time = 0.0

        # waves is used to concatenate all the fragments WAV files
        waves = numpy.array([])

        # espeak wrapper
        espeak = ESPEAKWrapper(logger=self.logger)

        if quit_after is not None:
            self._log(["Quit after reaching %.3f", quit_after])
        if backwards:
            self._log("Synthesizing backwards")

        # for each fragment, synthesize it and concatenate it
        num = 0
        num_chars = 0
        fragments = text_file.fragments
        if backwards:
            fragments = fragments[::-1]
        for fragment in fragments:

            # synthesize and get the duration of the output file
            self._log(["Synthesizing fragment %d", num])
            handler, tmp_destination = tempfile.mkstemp(
                suffix=".wav",
                dir=gf.custom_tmp_dir()
            )
            duration = espeak.synthesize(
                text=fragment.text,
                language=fragment.language,
                output_file_path=tmp_destination
            )

            # store for later output
            anchors.append([current_time, fragment.identifier, fragment.text])

            # increase the character counter
            num_chars += fragment.characters

            # concatenate to buffer
            self._log(["Fragment %d starts at: %f", num, current_time])
            if duration > 0:
                self._log(["Fragment %d duration: %f", num, duration])
                current_time += duration
                data, sample_frequency, encoding = wavread(tmp_destination)
                #
                # TODO this might result in memory swapping
                # if we have a large number of fragments
                # is there a better way?
                #
                # NOTE since append cannot be in place,
                # it seems that the only alternative is pre-allocating
                # the destination array,
                # possibly truncating or extending it as needed
                #
                if backwards:
                    waves = numpy.append(data, waves)
                else:
                    waves = numpy.append(waves, data)
#.........这里部分代码省略.........
开发者ID:fduch2k,项目名称:aeneas,代码行数:103,代码来源:synthesizer.py

示例6: ESPEAKWrapper

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
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])
#.........这里部分代码省略.........
开发者ID:fduch2k,项目名称:aeneas,代码行数:103,代码来源:espeakwrapper.py

示例7: AudioFile

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class AudioFile(object):
    """
    A class representing an audio file.

    The properties of the audio file
    (length, format, etc.)
    will be set by ``read_properties()``
    which will invoke an audio file probe.
    (Currently,
    :class:`aeneas.ffprobewrapper.FFPROBEWrapper`
    )

    If the file is a monoaural WAVE file,
    its data can be read and MFCCs can be extracted.

    :param file_path: the path to the audio file
    :type  file_path: string (path)
    :param logger: the logger object
    :type  logger: :class:`aeneas.logger.Logger`
    """

    TAG = "AudioFile"

    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

    def _log(self, message, severity=Logger.DEBUG):
        """ Log """
        self.logger.log(message, severity, self.TAG)

    def __str__(self):
        accumulator = ""
        accumulator += "File path:         %s\n" % self.file_path
        accumulator += "File size (bytes): %s\n" % gf.safe_int(self.file_size)
        accumulator += "Audio length (s):  %s\n" % gf.safe_float(self.audio_length)
        accumulator += "Audio format:      %s\n" % self.audio_format
        accumulator += "Audio sample rate: %s\n" % gf.safe_int(self.audio_sample_rate)
        accumulator += "Audio channels:    %s" % gf.safe_int(self.audio_channels)
        return accumulator

    @property
    def file_path(self):
        """
        The path of the audio file.

        :rtype: string
        """
        return self.__file_path
    @file_path.setter
    def file_path(self, file_path):
        self.__file_path = file_path

    @property
    def file_size(self):
        """
        The size, in bytes, of the audio file.

        :rtype: int
        """
        return self.__file_size
    @file_size.setter
    def file_size(self, file_size):
        self.__file_size = file_size

    @property
    def audio_length(self):
        """
        The length, in seconds, of the audio file.

        :rtype: float
        """
        return self.__audio_length
    @audio_length.setter
    def audio_length(self, audio_length):
        self.__audio_length = audio_length

    @property
    def audio_format(self):
        """
        The format of the audio file.

        :rtype: string
        """
        return self.__audio_format
    @audio_format.setter
    def audio_format(self, audio_format):
        self.__audio_format = audio_format

    @property
    def audio_sample_rate(self):
#.........这里部分代码省略.........
开发者ID:fduch2k,项目名称:aeneas,代码行数:103,代码来源:audiofile.py

示例8: FFPROBEWrapper

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class FFPROBEWrapper(object):
    """
    Wrapper around ``ffprobe`` to read the properties of an audio file.

    It will perform a call like::

        $ ffprobe -select_streams a -show_streams /path/to/audio/file.mp3

    and it will parse the first ``[STREAM]`` element returned::

            [STREAM]
            index=0
            codec_name=mp3
            codec_long_name=MP3 (MPEG audio layer 3)
            profile=unknown
            codec_type=audio
            codec_time_base=1/44100
            codec_tag_string=[0][0][0][0]
            codec_tag=0x0000
            sample_fmt=s16p
            sample_rate=44100
            channels=1
            channel_layout=mono
            bits_per_sample=0
            id=N/A
            r_frame_rate=0/0
            avg_frame_rate=0/0
            time_base=1/14112000
            start_pts=0
            start_time=0.000000
            duration_ts=1545083190
            duration=109.487188
            bit_rate=128000
            max_bit_rate=N/A
            bits_per_raw_sample=N/A
            nb_frames=N/A
            nb_read_frames=N/A
            nb_read_packets=N/A
            DISPOSITION:default=0
            DISPOSITION:dub=0
            DISPOSITION:original=0
            DISPOSITION:comment=0
            DISPOSITION:lyrics=0
            DISPOSITION:karaoke=0
            DISPOSITION:forced=0
            DISPOSITION:hearing_impaired=0
            DISPOSITION:visual_impaired=0
            DISPOSITION:clean_effects=0
            DISPOSITION:attached_pic=0
            [/STREAM]

    :param logger: the logger object
    :type  logger: :class:`aeneas.logger.Logger`
    """

    FFPROBE_PARAMETERS = ["-select_streams", "a", "-show_streams"]
    """ ``ffprobe`` parameters """

    STDERR_DURATION_REGEX = r"Duration: ([0-9]*):([0-9]*):([0-9]*)\.([0-9]*)"
    """ Regex to match ``ffprobe`` stderr duration values """

    STDOUT_BEGIN_STREAM = "[STREAM]"
    """ ``ffprobe`` stdout begin stream tag """

    STDOUT_CHANNELS = "channels"
    """ ``ffprobe`` stdout channels keyword """

    STDOUT_CODEC_NAME = "codec_name"
    """ ``ffprobe`` stdout codec name (format) keyword """

    STDOUT_END_STREAM = "[/STREAM]"
    """ ``ffprobe`` stdout end stream tag """

    STDOUT_DURATION = "duration"
    """ ``ffprobe`` stdout duration keyword """

    STDOUT_SAMPLE_RATE = "sample_rate"
    """ ``ffprobe`` stdout sample rate keyword """

    TAG = "FFPROBEWrapper"

    def __init__(self, logger=None):
        self.logger = logger
        if logger is None:
            self.logger = Logger()

    def _log(self, message, severity=Logger.DEBUG):
        """ Log """
        self.logger.log(message, severity, self.TAG)

    def read_properties(self, audio_file_path):
        """
        Read the properties of an audio file
        and return them as a dictionary.

        Example: ::

            d["index"]=0
            d["codec_name"]=mp3
            d["codec_long_name"]=MP3 (MPEG audio layer 3)
#.........这里部分代码省略.........
开发者ID:cambell-prince,项目名称:aeneas,代码行数:103,代码来源:ffprobewrapper.py

示例9: TextFile

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
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.

#.........这里部分代码省略.........
开发者ID:cambell-prince,项目名称:aeneas,代码行数:103,代码来源:textfile.py

示例10: SyncMap

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class SyncMap(object):
    """
    A synchronization map, that is, a list of
    :class:`aeneas.syncmap.SyncMapFragment`
    objects.
    """

    TAG = "SyncMap"

    def __init__(self, logger=None):
        self.fragments = []
        self.logger = Logger()
        if logger is not None:
            self.logger = logger

    def _log(self, message, severity=Logger.DEBUG):
        """ Log """
        self.logger.log(message, severity, self.TAG)

    def __len__(self):
        return len(self.fragments)

    def __str__(self):
        return "\n".join([str(f) for f in self.fragments])

    def append(self, fragment):
        """
        Append the given sync map fragment.

        :param fragment: the sync map fragment to be appended
        :type  fragment: :class:`aeneas.syncmap.SyncMapFragment`
        """
        self.fragments.append(fragment)

    @property
    def fragments(self):
        """
        The current list of sync map fragments.

        :rtype: list of :class:`aeneas.syncmap.SyncMapFragment`
        """
        return self.__fragments
    @fragments.setter
    def fragments(self, fragments):
        self.__fragments = fragments

    def clear(self):
        """
        Clear the sync map.
        """
        self._log("Clearing sync map")
        self.fragments = []

    def read(self, sync_map_format, input_file_path, parameters=None):
        """
        Read sync map fragments from the given file in the specified format,
        and append them the current (this) sync map.

        Return ``True`` if the call succeeded,
        ``False`` if an error occurred.

        :param sync_map_format: the format of the sync map
        :type  sync_map_format: string (from :class:`aeneas.syncmap.SyncMapFormat` enumeration)
        :param input_file_path: the path to the input file to read
        :type  input_file_path: string (path)
        :param parameters: additional parameters (e.g., for SMIL input)
        :type  parameters: dict
        :rtype: bool
        """
        self._log(["Input format:     '%s'", sync_map_format])
        self._log(["Input path:       '%s'", input_file_path])
        self._log(["Input parameters: '%s'", parameters])

        try:
            # open file for writing
            self._log("Opening output file")
            input_file = codecs.open(input_file_path, "r", "utf-8")

            # input from the requested format
            if sync_map_format == SyncMapFormat.CSV:
                self._read_csv(input_file, gf.time_from_ssmmm)
            elif sync_map_format == SyncMapFormat.CSVH:
                self._read_csv(input_file, gf.time_from_hhmmssmmm)
            elif sync_map_format == SyncMapFormat.CSVM:
                self._read_csv(input_file, gf.time_from_ssmmm)
            elif sync_map_format == SyncMapFormat.JSON:
                self._read_json(input_file)
            elif sync_map_format == SyncMapFormat.RBSE:
                self._read_rbse(input_file)
            elif sync_map_format == SyncMapFormat.SMIL:
                self._read_smil(input_file)
            elif sync_map_format == SyncMapFormat.SMILH:
                self._read_smil(input_file)
            elif sync_map_format == SyncMapFormat.SMILM:
                self._read_smil(input_file)
            elif sync_map_format == SyncMapFormat.SRT:
                self._read_srt(input_file)
            elif sync_map_format == SyncMapFormat.SSV:
                self._read_ssv(input_file, gf.time_from_ssmmm)
            elif sync_map_format == SyncMapFormat.SSVH:
#.........这里部分代码省略.........
开发者ID:cambell-prince,项目名称:aeneas,代码行数:103,代码来源:syncmap.py

示例11: AnalyzeContainer

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class AnalyzeContainer(object):
    """
    Analyze a given container and build the corresponding job.

    :param container: the container to be analyzed
    :type  container: :class:`aeneas.container.Container`
    :param logger: the logger object
    :type  logger: :class:`aeneas.logger.Logger`
    """

    TAG = "AnalyzeContainer"

    def __init__(self, container, logger=None):
        self.logger = logger
        if self.logger is None:
            self.logger = Logger()
        self.container = container

    def analyze(self):
        """
        Analyze the given container and
        return the corresponding job object.

        On error, it will return ``None``.

        :rtype: :class:`aeneas.job.Job`
        """
        if self.container.has_config_xml:
            self._log("Analyzing container with XML config file")
            return self._analyze_xml_config(config_contents=None)
        elif self.container.has_config_txt:
            self._log("Analyzing container with TXT config file")
            return self._analyze_txt_config(config_string=None)
        else:
            self._log("No configuration file in this container, returning None")
            return None

    def analyze_from_wizard(self, config_string):
        """
        Analyze the given container using the given config string
        and return the corresponding job.

        On error, it will return ``None``.

        :param config_string: the configuration string generated by the wizard
        :type  config_string: string
        :rtype: :class:`aeneas.job.Job`
        """
        self._log("Analyzing container with config string from wizard")
        return self._analyze_txt_config(config_string=config_string)

    def _log(self, message, severity=Logger.DEBUG):
        """ Log """
        self.logger.log(message, severity, self.TAG)

    def _analyze_txt_config(self, config_string=None):
        """
        Analyze the given container and return the corresponding job.

        If ``config_string`` is ``None``,
        try reading it from the TXT config file inside the container.

        :param config_string: the configuration string
        :type  config_string: string
        :rtype: :class:`aeneas.job.Job`
        """
        # TODO break this function down into smaller functions
        self._log("Analyzing container with TXT config string")

        if config_string is None:
            self._log("Analyzing container with TXT config file")
            config_entry = self.container.entry_config_txt
            self._log(["Found TXT config entry '%s'", config_entry])
            config_dir = os.path.dirname(config_entry)
            self._log(["Directory of TXT config entry: '%s'", config_dir])
            self._log(["Reading TXT config entry: '%s'", config_entry])
            config_contents = self.container.read_entry(config_entry)
            #self._log("Removing BOM")
            #config_contents = gf.remove_bom(config_contents)
            self._log("Converting config contents to config string")
            config_string = gf.config_txt_to_string(config_contents)
        else:
            self._log(["Analyzing container with TXT config string '%s'", config_string])
            config_dir = ""
            #self._log("Removing BOM")
            #config_string = gf.remove_bom(config_string)

        # create the Job object to be returned
        self._log("Creating the Job object")
        job = Job(config_string)

        # get the entries in this container
        self._log("Getting entries")
        entries = self.container.entries()

        # convert the config string to dict
        self._log("Converting config string into config dict")
        parameters = gf.config_string_to_dict(config_string)

        # compute the root directory for the task assets
#.........这里部分代码省略.........
开发者ID:cambell-prince,项目名称:aeneas,代码行数:103,代码来源:analyzecontainer.py

示例12: Container

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class Container(object):
    """
    An abstraction for different archive formats like ZIP or TAR,
    exposing common functions like extracting all files or
    a single file, listing the files, etc.

    An (uncompressed) directory can be used in lieu of a compressed file.

    :param file_path: the path to the container file (or directory)
    :type  file_path: string (path)
    :param container_format: the format of the container
    :type  container_format: :class:`aeneas.container.ContainerFormat`
    :param logger: the logger object
    :type  logger: :class:`aeneas.logger.Logger`
    """

    TAG = "Container"

    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()

    def _log(self, message, severity=Logger.DEBUG):
        """ Log """
        self.logger.log(message, severity, self.TAG)

    @property
    def file_path(self):
        """
        The path of this container.

        :rtype: string (path)
        """
        return self.__file_path
    @file_path.setter
    def file_path(self, file_path):
        self.__file_path = file_path

    @property
    def container_format(self):
        """
        The format of this container.

        :rtype: :class:`aeneas.container.ContainerFormat`
        """
        return self.__container_format
    @container_format.setter
    def container_format(self, container_format):
        self.__container_format = container_format

    @property
    def has_config_xml(self):
        """
        Return ``True`` if there is an XML config file in this container,
        ``False`` otherwise.

        :rtype: bool
        """
        return self.find_entry(gc.CONFIG_XML_FILE_NAME, exact=False) is not None

    @property
    def entry_config_xml(self):
        """
        Return the entry (path inside the container)
        of the XML config file in this container,
        or ``None`` if not present.

        :rtype: string (path)
        """
        return self.find_entry(gc.CONFIG_XML_FILE_NAME, exact=False)

    @property
    def has_config_txt(self):
        """
        Return ``True`` if there is a TXT config file in this container,
        ``False`` otherwise.

        :rtype: bool
        """
        return self.find_entry(gc.CONFIG_TXT_FILE_NAME, exact=False) is not None

    @property
    def entry_config_txt(self):
        """
        Return the entry (path inside the container)
        of the TXT config file in this container,
        or ``None`` if not present.

        :rtype: string (path)
        """
        return self.find_entry(gc.CONFIG_TXT_FILE_NAME, exact=False)

    @property
    def is_safe(self):
#.........这里部分代码省略.........
开发者ID:cambell-prince,项目名称:aeneas,代码行数:103,代码来源:container.py

示例13: TextFile

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
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 != None:
            self.logger = logger
        if (self.file_path != None) and (self.file_format != 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):
        self.logger.log(message, severity, self.TAG)

    @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 set_language(self, language):
        """
        Set the given language for all the text fragments.

        :param language: the language of the text fragments
        :type  language: string (from :class:`aeneas.language.Language` enumeration)
        """
        self._log("Setting language: '%s'" % language)
        for fragment in self.fragments:
            fragment.language = language

    def clear(self):
        """
        Clear the list of text fragments.
        """
        self._log("Clearing text fragments")
        self.fragments = []

    def read_from_list(self, lines):
        """
        Read text fragments from a given list of strings::

            [fragment_1, fragment_2, ..., fragment_n]

        :param lines: the text fragments
        :type  lines: list of strings
        """
        self._log("Reading text fragments from list")
        self._read_plain(lines)

    def read_from_list_with_ids(self, lines):
        """
        Read text fragments from a given list of lists::

            [[id_1, text_1], [id_2, text_2], ..., [id_n, text_n]].

        :param lines: the list of ``[id, text]`` fragments (see above)
        :type  lines: list of pairs (see above)
        """
        self._log("Reading text fragments from list with ids")
        self._create_text_fragments(lines)

    def _read_from_file(self):
        """
        Read text fragments from file.
        """

        # test if we can read the given file
        if not os.path.isfile(self.file_path):
            msg = "File '%s' cannot be read" % self.file_path
            self._log(msg, Logger.CRITICAL)
            raise OSError(msg)
#.........这里部分代码省略.........
开发者ID:cbeer,项目名称:aeneas,代码行数:103,代码来源:textfile.py

示例14: SD

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class SD(object):
    """
    The SD extractor.

    :param audio_file: the audio file
    :type  audio_file: :class:`aeneas.audiofile.AudioFile`
    :param text_file: the text file
    :type  text_file: :class:`aeneas.textfile.TextFile`
    :param frame_rate: the MFCC frame rate, in frames per second. Default:
                       :class:`aeneas.globalconstants.MFCC_FRAME_RATE`
    :type  frame_rate: int
    :param logger: the logger object
    :type  logger: :class:`aeneas.logger.Logger`
    """

    TAG = "SD"

    # TODO eliminate these magic numbers
    MAX_RUNS_NO_IMPROVEMENT = 20
    MAX_RUNS_WITH_MIN_LENGTH = 20
    QUERY_FACTOR = 2.0
    AUDIO_FACTOR = 6.0

    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

    def _log(self, message, severity=Logger.DEBUG):
        """ Log """
        self.logger.log(message, severity, self.TAG)

    def detect_interval(
            self,
            min_head_length=gc.SD_MIN_HEAD_LENGTH,
            max_head_length=gc.SD_MAX_HEAD_LENGTH,
            min_tail_length=gc.SD_MIN_TAIL_LENGTH,
            max_tail_length=gc.SD_MAX_TAIL_LENGTH,
            metric=SDMetric.VALUE
        ):
        """
        Detect the audio interval.

        :param max_head_length: estimated maximum head length
        :type  max_head_length: float
        :param max_tail_length: estimated maximum tail length
        :type  max_tail_length: float
        :param metric: the metric to be used when comparing candidates
        :type  metric: :class:`aeneas.sd.SDMetric`
        :rtype: (float, float)
        """
        head = self.detect_head(min_head_length, max_head_length, metric)
        tail = self.detect_tail(min_tail_length, max_tail_length, metric)
        begin = head
        end = self.audio_file.audio_length - tail
        self._log(["Audio length: %.3f", self.audio_file.audio_length])
        self._log(["Head length:  %.3f", head])
        self._log(["Tail length:  %.3f", tail])
        self._log(["Begin:        %.3f", begin])
        self._log(["End:          %.3f", end])
        if (begin >= 0) and (end > begin):
            self._log(["Returning %.3f %.3f", begin, end])
            return (begin, end)
        self._log("Returning (0.0, 0.0)")
        return (0.0, 0.0)

    def detect_head(
            self,
            min_head_length=gc.SD_MIN_HEAD_LENGTH,
            max_head_length=gc.SD_MAX_HEAD_LENGTH,
            metric=SDMetric.VALUE
        ):
        """
        Detect the audio head.

        :param min_head_length: estimated minimum head length
        :type  min_head_length: float
        :param max_head_length: estimated maximum head length
        :type  max_head_length: float
        :param metric: the metric to be used when comparing candidates
        :type  metric: :class:`aeneas.sd.SDMetric`
        :rtype: float
        """
        self._extract_mfcc()
        self._extract_speech()
        self.audio_file.clear_data()
        head = 0.0
        try:
            head = self._detect_start(min_head_length, max_head_length, metric, False)
        except Exception as e:
#.........这里部分代码省略.........
开发者ID:cambell-prince,项目名称:aeneas,代码行数:103,代码来源:sd.py

示例15: DTWAligner

# 需要导入模块: from aeneas.logger import Logger [as 别名]
# 或者: from aeneas.logger.Logger import log [as 别名]
class DTWAligner(object):
    """
    The MFCC extractor and wave aligner.

    :param wave_path_1: the path to the real wav file
    :type  wave_path_1: string (path)
    :param wave_path_2: the path to the synthesized wav file
    :type  wave_path_2: string (path)
    :param frame_rate: the MFCC frame rate, in frames per second. Default:
                       :class:`aeneas.globalconstants.ALIGNER_FRAME_RATE`
    :type  frame_rate: int
    :param margin: the margin to be used in DTW stripe algorithms, in seconds.
                   Default: :class:`aeneas.globalconstants.ALIGNER_MARGIN`
    :type  margin: int
    :param algorithm: the DTW algorithm to be used when aligning the waves
    :type  algorithm: :class:`aeneas.dtw.DTWAlgorithm`
    :param logger: the logger object
    :type  logger: :class:`aeneas.logger.Logger`
    """

    TAG = "DTWAligner"

    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

    def _log(self, message, severity=Logger.DEBUG):
        self.logger.log(message, severity, self.TAG)

    def compute_mfcc(self):
        """
        Compute the MFCCs of the two waves,
        and store them internally.
        """
        if (self.wave_path_1 != None) and (os.path.isfile(self.wave_path_1)):
            self._log("Computing MFCCs for wave 1")
            self.wave_mfcc_1, self.wave_len_1 = self._compute_mfcc(self.wave_path_1)
        else:
            # TODO raise
            pass

        if (self.wave_path_2 != None) and (os.path.isfile(self.wave_path_2)):
            self._log("Computing MFCCs for wave 2")
            self.wave_mfcc_2, self.wave_len_2 = self._compute_mfcc(self.wave_path_2)
        else:
            # TODO raise
            pass

    def _compute_mfcc(self, path):
        self._log("Computing MFCCs for '%s'" % path)
        self._log("Loading wav file")
        data, sample_frequency, encoding = wavread(path)
        length = (float(len(data)) / sample_frequency)
        self._log("Sample length:    %f" % length)
        self._log("Sample frequency: %f" % sample_frequency)
        self._log("Sample encoding:  %s" % encoding)
        self._log("Computing MFCCs")
        computer = MFCC(samprate=sample_frequency, frate=self.frame_rate)
        result = computer.sig2s2mfc(data).transpose()
        self._log("Returning MFCCs")
        return (result, length)

    def compute_path(self):
        """
        Compute the min cost path between the two waves,
        and store it interally.
        """
        # setup
        dtw = None
        algorithm = self.algorithm
        delta = self.frame_rate * (self.margin * 2)
        mfcc2_size = self.wave_mfcc_2.shape[1]
        self._log("Requested algorithm: '%s'" % algorithm)
        self._log("delta = %d" % delta)
        self._log("m = %d" % mfcc2_size)
        # check if delta is >= length of synt wave
        if mfcc2_size <= delta:
            self._log("We have mfcc2_size <= delta")
            if gc.ALIGNER_USE_EXACT_ALGO_WHEN_MARGIN_TOO_LARGE:
                self._log("Selecting EXACT algorithm")
                algorithm = DTWAlgorithm.EXACT
#.........这里部分代码省略.........
开发者ID:dburt,项目名称:aeneas,代码行数:103,代码来源:dtw.py


注:本文中的aeneas.logger.Logger.log方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。