def __init__(self, job=None, logger=None): self.job = job self.working_directory = None self.tmp_directory = None self.logger = logger if self.logger is None: self.logger = Logger()
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)
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 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)
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)
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)
def test_execute(self): config_string = "task_language=en|os_task_file_format=txt|os_task_file_name=output_head.txt|is_text_type=plain|is_audio_file_head_length=11.960|is_audio_file_process_length=31.640" task = Task(config_string) task.audio_file_path_absolute = "../aeneas/tests/res/container/job/assets/p001.mp3" task.text_file_path_absolute = "../aeneas/tests/res/inputtext/sonnet_plain_head_length.txt" logger = Logger(tee=True) executor = ExecuteTask(task, logger=logger) result = executor.execute() self.assertTrue(result) task.sync_map_file_path_absolute = "/tmp/output_head_length.txt" path = task.output_sync_map_file() self.assertNotEqual(path, None)
def test_execute(self): config_string = "task_language=en|os_task_file_format=smil|os_task_file_name=p001.smil|os_task_file_smil_audio_ref=p001.mp3|os_task_file_smil_page_ref=p001.xhtml|is_text_type=unparsed|is_text_unparsed_id_regex=f[0-9]+|is_text_unparsed_id_sort=numeric" task = Task(config_string) task.audio_file_path_absolute = "../aeneas/tests/res/container/job/assets/p001.mp3" task.text_file_path_absolute = "../aeneas/tests/res/container/job/assets/p001.xhtml" logger = Logger(tee=True) executor = ExecuteTask(task, logger=logger) result = executor.execute() self.assertTrue(result) task.sync_map_file_path_absolute = "/tmp/p001.smil" path = task.output_sync_map_file() self.assertNotEqual(path, None)
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 __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 test_execute(self): input_path = "../aeneas/tests/res/container/job.zip" output_path = "/tmp/" logger = Logger(tee=True) executor = ExecuteJob(job=None, logger=logger) executor.load_job_from_container(input_path) self.assertNotEqual(executor.job, None) result = executor.execute() self.assertTrue(result) result, path = executor.write_output_container(output_path) self.assertTrue(result) self.assertTrue(os.path.exists(path)) executor.clean()
def main(): """ Entry point """ if len(sys.argv) < 3: usage() return container_path = sys.argv[1] config_string = None verbose = (sys.argv[-1] == "-v") number_of_arguments = 4 if verbose: number_of_arguments += 1 if len(sys.argv) >= number_of_arguments: config_string = sys.argv[2] output_dir = sys.argv[3] else: output_dir = sys.argv[2] logger = Logger(tee=verbose) executor = ExecuteJob(logger=logger) if not gf.can_run_c_extension(): print "[WARN] Unable to load Python C Extensions" print "[WARN] Running the slower pure Python code" print "[WARN] See the README file for directions to compile the Python C Extensions" print "[INFO] Loading job from container..." result = executor.load_job_from_container(container_path, config_string) print "[INFO] Loading job from container... done" if not result: print "[ERRO] The job cannot be loaded from the specified container" return print "[INFO] Executing..." result = executor.execute() print "[INFO] Executing... done" if not result: print "[ERRO] An error occurred while executing the job" return print "[INFO] Creating output container..." result, path = executor.write_output_container(output_dir) print "[INFO] Creating output container... done" if result: print "[INFO] Created %s" % path else: print "[ERRO] An error occurred while writing the output container" executor.clean(True)
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 __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()
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
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
def run_test_multi(self, msg): logger = Logger(tee=False) logger.log(msg) self.assertEqual(len(logger), 1)
def __init__(self, container, logger=None): self.logger = logger if self.logger is None: self.logger = Logger() self.container = container
def test_job_logger(self): logger = Logger() job = Job(logger=logger)
def __init__(self, logger=None): self.logger = logger if logger is None: self.logger = Logger()
def run(self, arguments, show_help=True): """ Program entry point. Please note that the first item in ``arguments`` is discarded, as it is assumed to be the script/invocation name; pass a "dumb" placeholder if you call this method with an argument different that ``sys.argv``. :param arguments: the list of arguments :type arguments: list :param show_help: if ``False``, do not show help on ``-h`` and ``--help`` :type show_help: bool :rtype: int """ # convert arguments into Unicode strings if self.use_sys: # check that sys.stdin.encoding and sys.stdout.encoding are set to utf-8 if not gf.FROZEN: if sys.stdin.encoding not in ["UTF-8", "UTF8"]: self.print_warning( u"The default input encoding is not UTF-8.") self.print_warning( u"You might want to set 'PYTHONIOENCODING=UTF-8' in your shell." ) if sys.stdout.encoding not in ["UTF-8", "UTF8"]: self.print_warning( u"The default output encoding is not UTF-8.") self.print_warning( u"You might want to set 'PYTHONIOENCODING=UTF-8' in your shell." ) # decode using sys.stdin.encoding args = [gf.safe_unicode_stdin(arg) for arg in arguments] else: # decode using utf-8 (but you should pass Unicode strings as parameters anyway) args = [gf.safe_unicode(arg) for arg in arguments] if show_help: if u"-h" in args: return self.print_help(short=True) if u"--help" in args: return self.print_help(short=False) if u"--version" in args: return self.print_name_version() # store formal arguments self.formal_arguments_raw = arguments self.formal_arguments = args # to obtain the actual arguments, # remove the first one and "special" switches args = args[1:] set_args = set(args) # set verbosity, if requested for flag in set([u"-v", u"--verbose"]) & set_args: self.verbose = True args.remove(flag) for flag in set([u"-vv", u"--very-verbose"]) & set_args: self.verbose = True self.very_verbose = True args.remove(flag) # set RuntimeConfiguration string, if specified for flag in [u"-r", u"--runtime-configuration"]: rconf_string = self.has_option_with_value(flag, actual_arguments=False) if rconf_string is not None: self.rconf = RuntimeConfiguration(rconf_string) args.remove("%s=%s" % (flag, rconf_string)) # set log file path, if requested log_path = None for flag in [u"-l", u"--log"]: log_path = self.has_option_with_value(flag, actual_arguments=False) if log_path is not None: args.remove("%s=%s" % (flag, log_path)) elif flag in set_args: handler, log_path = gf.tmp_file( suffix=u".log", root=self.rconf[RuntimeConfiguration.TMP_PATH]) args.remove(flag) if log_path is not None: self.log_file_path = log_path # if no actual arguments left, print help if (len(args) < 1) and (show_help): return self.print_help(short=True) # store actual arguments self.actual_arguments = args # create logger self.logger = Logger(tee=self.verbose, tee_show_datetime=self.very_verbose) self.log([u"Formal arguments: %s", self.formal_arguments]) self.log([u"Actual arguments: %s", self.actual_arguments]) self.log([u"Runtime configuration: '%s'", self.rconf.config_string()]) # perform command exit_code = self.perform_command() self.log([u"Execution completed with code %d", exit_code]) # output log if requested if self.log_file_path is not None: self.log([ u"User requested saving log to file '%s'", self.log_file_path ]) self.logger.write(self.log_file_path) if self.use_sys: self.print_info(u"Log written to file '%s'" % self.log_file_path) return self.exit(exit_code)
def test_synthesize_logger(self): logger = Logger() self.perform("res/inputtext/sonnet_plain.txt", 15, logger=logger)
def __init__(self, parameters=FFMPEG_PARAMETERS_DEFAULT, logger=None): self.parameters = parameters self.logger = logger if self.logger is None: self.logger = Logger() self._log(["Initialized with parameters '%s'", self.parameters])
def test_loggable_rconf_logger(self): logger = Logger() rconf = RuntimeConfiguration() loggable = Loggable(rconf=rconf, logger=logger) self.assertEqual(rconf, loggable.rconf) self.assertEqual(logger, loggable.logger)
def test_task_logger(self): logger = Logger() task = Task(logger=logger)
def test_synthesize_logger(self): logger = Logger() result = self.perform("res/inputtext/sonnet_plain.txt", logger=logger) self.assertEqual(len(result[0]), 15)
def __init__(self, task, logger=None): self.task = task self.cleanup_info = [] self.logger = logger if self.logger is None: self.logger = Logger()
def main(): """ Entry point """ if len(sys.argv) < 5: usage() return language = sys.argv[1] text_file_path = sys.argv[2] text_format = sys.argv[3] audio_file_path = sys.argv[-1] verbose = False parameters = {} for i in range(4, len(sys.argv) - 1): args = sys.argv[i].split("=") if len(args) == 1: verbose = (args[0] in ["v", "-v", "verbose", "--verbose"]) if len(args) == 2: key, value = args if key == "id_regex": parameters[gc.PPN_JOB_IS_TEXT_UNPARSED_ID_REGEX] = value if key == "class_regex": parameters[gc.PPN_JOB_IS_TEXT_UNPARSED_CLASS_REGEX] = value if key == "sort": parameters[gc.PPN_JOB_IS_TEXT_UNPARSED_ID_SORT] = value if key == "min_head_length": parameters["min_head_length"] = float(value) if key == "max_head_length": parameters["max_head_length"] = float(value) if key == "min_tail_length": parameters["min_head_length"] = float(value) if key == "max_tail_length": parameters["max_tail_length"] = float(value) if not gf.can_run_c_extension(): print "[WARN] Unable to load Python C Extensions" print "[WARN] Running the slower pure Python code" print "[WARN] See the README file for directions to compile the Python C Extensions" logger = Logger(tee=verbose) print "[INFO] Reading audio..." tmp_handler, tmp_file_path = tempfile.mkstemp(suffix=".wav", dir=gf.custom_tmp_dir()) converter = FFMPEGWrapper(logger=logger) converter.convert(audio_file_path, tmp_file_path) audio_file = AudioFile(tmp_file_path) print "[INFO] Reading audio... done" print "[INFO] Reading text..." if text_format == "list": text_file = TextFile() text_file.read_from_list(text_file_path.split("|")) else: text_file = TextFile(text_file_path, text_format, parameters) text_file.set_language(language) print "[INFO] Reading text... done" print "[INFO] Detecting audio interval..." sd = SD(audio_file, text_file, logger=logger) min_head_length = gc.SD_MIN_HEAD_LENGTH if "min_head_length" in parameters: min_head_length = parameters["min_head_length"] max_head_length = gc.SD_MAX_HEAD_LENGTH if "max_head_length" in parameters: max_head_length = parameters["max_head_length"] min_tail_length = gc.SD_MIN_TAIL_LENGTH if "min_tail_length" in parameters: min_tail_length = parameters["min_tail_length"] max_tail_length = gc.SD_MAX_TAIL_LENGTH if "max_tail_length" in parameters: max_tail_length = parameters["max_tail_length"] start, end = sd.detect_interval(min_head_length, max_head_length, min_tail_length, max_tail_length) zero = 0 audio_len = audio_file.audio_length head_len = start text_len = end - start tail_len = audio_len - end print "[INFO] Detecting audio interval... done" print "[INFO] " print "[INFO] Head: %.3f %.3f (%.3f)" % (zero, start, head_len) print "[INFO] Text: %.3f %.3f (%.3f)" % (start, end, text_len) print "[INFO] Tail: %.3f %.3f (%.3f)" % (end, audio_len, tail_len) print "[INFO] " zero_h = gf.time_to_hhmmssmmm(0) start_h = gf.time_to_hhmmssmmm(start) end_h = gf.time_to_hhmmssmmm(end) audio_len_h = gf.time_to_hhmmssmmm(audio_len) head_len_h = gf.time_to_hhmmssmmm(head_len) text_len_h = gf.time_to_hhmmssmmm(text_len) tail_len_h = gf.time_to_hhmmssmmm(tail_len) print "[INFO] Head: %s %s (%s)" % (zero_h, start_h, head_len_h) print "[INFO] Text: %s %s (%s)" % (start_h, end_h, text_len_h) print "[INFO] Tail: %s %s (%s)" % (end_h, audio_len_h, tail_len_h) #print "[INFO] Cleaning up..." cleanup(tmp_handler, tmp_file_path)
def test_loggable_logger(self): logger = Logger() loggable = Loggable(logger=logger) self.assertIsNotNone(loggable.rconf) self.assertEqual(logger, loggable.logger)
def __init__(self, algorithm, logger=None): self.algorithm = algorithm self.logger = logger if self.logger is None: self.logger = Logger()