本文整理汇总了Python中aeneas.textfile.TextFile.read_from_list方法的典型用法代码示例。如果您正苦于以下问题:Python TextFile.read_from_list方法的具体用法?Python TextFile.read_from_list怎么用?Python TextFile.read_from_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aeneas.textfile.TextFile
的用法示例。
在下文中一共展示了TextFile.read_from_list方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import read_from_list [as 别名]
def main():
""" Entry point """
if len(sys.argv) < 3:
usage()
return
file_path = sys.argv[1]
text_format = sys.argv[2]
parameters = {}
for i in range(3, len(sys.argv)):
args = sys.argv[i].split("=")
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 text_format == "list":
text_file = TextFile()
text_file.read_from_list(file_path.split("|"))
else:
text_file = TextFile(file_path, text_format, parameters)
print str(text_file)
示例2: test_read_from_list
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import read_from_list [as 别名]
def test_read_from_list(self):
tfl = TextFile()
text_list = [
"fragment 1",
"fragment 2",
"fragment 3",
"fragment 4",
"fragment 5"
]
tfl.read_from_list(text_list)
self.assertEqual(len(tfl), 5)
示例3: get_text_file
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import read_from_list [as 别名]
def get_text_file(self, text_format, text, parameters):
if text_format == u"list":
text_file = TextFile(logger=self.logger)
text_file.read_from_list(text.split(u"|"))
return text_file
else:
if text_format not in TextFileFormat.ALLOWED_VALUES:
self.print_error(u"File format '%s' is not allowed" % (text_format))
self.print_error(u"Allowed text file formats: %s" % (" ".join(TextFileFormat.ALLOWED_VALUES)))
return None
try:
return TextFile(text, text_format, parameters, logger=self.logger)
except OSError:
self.print_error(u"Cannot read file '%s'" % (text))
return None
示例4: main
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import read_from_list [as 别名]
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)
#.........这里部分代码省略.........