本文整理汇总了Python中aeneas.textfile.TextFile.set_language方法的典型用法代码示例。如果您正苦于以下问题:Python TextFile.set_language方法的具体用法?Python TextFile.set_language怎么用?Python TextFile.set_language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aeneas.textfile.TextFile
的用法示例。
在下文中一共展示了TextFile.set_language方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: perform
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def perform(self, path, logger=None, quit_after=None, backwards=False):
handler, output_file_path = tempfile.mkstemp(suffix=".wav")
tfl = TextFile(get_abs_path(path), TextFileFormat.PLAIN)
tfl.set_language(Language.EN)
synth = Synthesizer(logger=logger)
result = synth.synthesize(tfl, output_file_path, quit_after=quit_after, backwards=backwards)
delete_file(handler, output_file_path)
return result
示例2: test_synthesize_with_unicode
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def test_synthesize_with_unicode(self):
handler, output_file_path = tempfile.mkstemp(suffix=".wav")
tfl = TextFile(get_abs_path("res/inputtext/de_utf8.txt"), TextFileFormat.PARSED)
tfl.set_language(Language.DE)
synth = Synthesizer()
anchors = synth.synthesize(tfl, output_file_path)
self.assertGreater(len(anchors), 0)
os.remove(output_file_path)
示例3: test_synthesize
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def test_synthesize(self):
handler, output_file_path = tempfile.mkstemp(suffix=".wav")
tfl = TextFile(get_abs_path("res/inputtext/sonnet_plain.txt"), TextFileFormat.PLAIN)
tfl.set_language(Language.EN)
synth = Synthesizer()
anchors = synth.synthesize(tfl, output_file_path)
self.assertGreater(len(anchors), 0)
os.remove(output_file_path)
示例4: test_set_language
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def test_set_language(self):
tfl = TextFile(get_abs_path("res/inputtext/sonnet_plain.txt"), TextFileFormat.PLAIN)
self.assertEqual(len(tfl), 15)
tfl.set_language(Language.EN)
for fragment in tfl.fragments:
self.assertEqual(fragment.language, Language.EN)
tfl.set_language(Language.IT)
for fragment in tfl.fragments:
self.assertEqual(fragment.language, Language.IT)
示例5: inner
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def inner(c_ext, cew_subprocess):
handler, output_file_path = gf.tmp_file(suffix=".wav")
tfl = TextFile(gf.absolute_path(path, __file__), TextFileFormat.PLAIN)
tfl.set_language(Language.ENG)
synth = Synthesizer(logger=logger)
synth.rconf[RuntimeConfiguration.C_EXTENSIONS] = c_ext
synth.rconf[RuntimeConfiguration.CEW_SUBPROCESS_ENABLED] = cew_subprocess
result = synth.synthesize(tfl, output_file_path, quit_after=quit_after, backwards=backwards)
gf.delete_file(handler, output_file_path)
self.assertEqual(len(result[0]), expected)
if expected2 is not None:
self.assertAlmostEqual(result[1], expected2, places=0)
示例6: test_no_fragments
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def test_no_fragments(self):
tfl = TextFile()
tfl.set_language(self.TTS_LANGUAGE)
self.synthesize(tfl, expected_exc=ValueError)
示例7: test_multiple_no_fragments
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def test_multiple_no_fragments(self):
tfl = TextFile()
tfl.set_language(ESPEAKWrapper.ENG)
with self.assertRaises(ValueError):
self.synthesize_multiple(tfl)
示例8: Task
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
#.........这里部分代码省略.........
of the sync map inside the container.
Otherwise, the sync map file will be created at the path
``self.sync_map_file_path_absolute``.
Return the the path of the sync map file created,
or ``None`` if an error occurred.
:param string container_root_path: the path to the root directory
for the output container
:rtype: string
"""
if self.sync_map is None:
self.log_exc(u"The sync_map object has not been set", None, True, TypeError)
if (container_root_path is not None) and (self.sync_map_file_path is None):
self.log_exc(u"The (internal) path of the sync map has been set", None, True, TypeError)
self.log([u"container_root_path is %s", container_root_path])
self.log([u"self.sync_map_file_path is %s", self.sync_map_file_path])
self.log([u"self.sync_map_file_path_absolute is %s", self.sync_map_file_path_absolute])
if (container_root_path is not None) and (self.sync_map_file_path is not None):
path = os.path.join(container_root_path, self.sync_map_file_path)
elif self.sync_map_file_path_absolute:
path = self.sync_map_file_path_absolute
gf.ensure_parent_directory(path)
self.log([u"Output sync map to %s", path])
sync_map_format = self.configuration["o_format"]
audio_ref = self.configuration["o_smil_audio_ref"]
page_ref = self.configuration["o_smil_page_ref"]
self.log([u"sync_map_format is %s", sync_map_format])
self.log([u"page_ref is %s", page_ref])
self.log([u"audio_ref is %s", audio_ref])
self.log(u"Calling sync_map.write...")
afpa = self.audio_file_path_absolute
if afpa is not None:
afpa = os.path.abspath(afpa)
parameters = {
"audio_file_path_absolute": afpa,
gc.PPN_TASK_OS_FILE_SMIL_PAGE_REF : page_ref,
gc.PPN_TASK_OS_FILE_SMIL_AUDIO_REF : audio_ref
}
self.sync_map.write(sync_map_format, path, parameters)
self.log(u"Calling sync_map.write... done")
return path
def _populate_audio_file(self):
"""
Create the ``self.audio_file`` object by reading
the audio file at ``self.audio_file_path_absolute``.
"""
self.log(u"Populate audio file...")
if self.audio_file_path_absolute is not None:
self.log([u"audio_file_path_absolute is '%s'", self.audio_file_path_absolute])
self.audio_file = AudioFile(
file_path=self.audio_file_path_absolute,
logger=self.logger
)
self.audio_file.read_properties()
else:
self.log(u"audio_file_path_absolute is None")
self.log(u"Populate audio file... done")
def _populate_text_file(self):
"""
Create the ``self.text_file`` object by reading
the text file at ``self.text_file_path_absolute``.
"""
self.log(u"Populate text file...")
if (
(self.text_file_path_absolute is not None) and
(self.configuration["language"] is not None)
):
# the following values might be None
parameters = {
gc.PPN_TASK_IS_TEXT_FILE_IGNORE_REGEX : self.configuration["i_t_ignore_regex"],
gc.PPN_TASK_IS_TEXT_FILE_TRANSLITERATE_MAP : self.configuration["i_t_transliterate_map"],
gc.PPN_TASK_IS_TEXT_MPLAIN_WORD_SEPARATOR : self.configuration["i_t_mplain_word_separator"],
gc.PPN_TASK_IS_TEXT_MUNPARSED_L1_ID_REGEX : self.configuration["i_t_munparsed_l1_id_regex"],
gc.PPN_TASK_IS_TEXT_MUNPARSED_L2_ID_REGEX : self.configuration["i_t_munparsed_l2_id_regex"],
gc.PPN_TASK_IS_TEXT_MUNPARSED_L3_ID_REGEX : self.configuration["i_t_munparsed_l3_id_regex"],
gc.PPN_TASK_IS_TEXT_UNPARSED_CLASS_REGEX : self.configuration["i_t_unparsed_class_regex"],
gc.PPN_TASK_IS_TEXT_UNPARSED_ID_REGEX : self.configuration["i_t_unparsed_id_regex"],
gc.PPN_TASK_IS_TEXT_UNPARSED_ID_SORT : self.configuration["i_t_unparsed_id_sort"],
gc.PPN_TASK_OS_FILE_ID_REGEX : self.configuration["o_id_regex"]
}
self.text_file = TextFile(
file_path=self.text_file_path_absolute,
file_format=self.configuration["i_t_format"],
parameters=parameters,
logger=self.logger
)
self.text_file.set_language(self.configuration["language"])
else:
self.log(u"text_file_path_absolute and/or language is None")
self.log(u"Populate text file... done")
示例9: Task
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
#.........这里部分代码省略.........
def audio_file_path_absolute(self, audio_file_path_absolute):
self.__audio_file_path_absolute = audio_file_path_absolute
self._populate_audio_file()
@property
def text_file_path_absolute(self):
"""
The absolute path of the text file.
:rtype: string (path)
"""
return self.__text_file_path_absolute
@text_file_path_absolute.setter
def text_file_path_absolute(self, text_file_path_absolute):
self.__text_file_path_absolute = text_file_path_absolute
self._populate_text_file()
@property
def sync_map_file_path_absolute(self):
"""
The absolute path of the sync map file.
:rtype: string (path)
"""
return self.__sync_map_file_path_absolute
@sync_map_file_path_absolute.setter
def sync_map_file_path_absolute(self, sync_map_file_path_absolute):
self.__sync_map_file_path_absolute = sync_map_file_path_absolute
def _populate_audio_file(self):
"""
Create the ``self.audio_file`` object by reading
the audio file at ``self.audio_file_path_absolute``.
"""
if self.audio_file_path_absolute is not None:
self.audio_file = AudioFile(
file_path=self.audio_file_path_absolute,
logger=None
)
self.audio_file.read_properties()
def _populate_text_file(self):
"""
Create the ``self.text_file`` object by reading
the text file at ``self.text_file_path_absolute``.
"""
if ((self.text_file_path_absolute is not None) and
(self.configuration.language is not None)):
parameters = dict()
parameters[gc.PPN_TASK_IS_TEXT_UNPARSED_CLASS_REGEX] = self.configuration.is_text_unparsed_class_regex
parameters[gc.PPN_TASK_IS_TEXT_UNPARSED_ID_REGEX] = self.configuration.is_text_unparsed_id_regex
parameters[gc.PPN_TASK_IS_TEXT_UNPARSED_ID_SORT] = self.configuration.is_text_unparsed_id_sort
self.text_file = TextFile(
file_path=self.text_file_path_absolute,
file_format=self.configuration.is_text_file_format,
parameters=parameters,
logger=None
)
self.text_file.set_language(self.configuration.language)
def output_sync_map_file(self, container_root_path=None):
"""
Output the sync map file for this task.
If ``container_root_path`` is specified,
the output sync map file will be created
at the path obtained by joining
the ``container_root_path`` and the relative path
of the sync map inside the container.
Otherwise, the sync map file will be created at the path
``sync_map_file_path_absolute``.
Return the the path of the sync map file created,
or ``None`` if an error occurred.
:param container_root_path: the path to the root directory
for the output container
:type container_root_path: string (path)
:rtype: return the path of the sync map file created
"""
if self.sync_map is None:
return None
if (container_root_path is not None) and (self.sync_map_file_path is None):
return None
if (container_root_path is not None) and (self.sync_map_file_path is not None):
path = os.path.join(container_root_path, self.sync_map_file_path)
elif self.sync_map_file_path_absolute:
path = self.sync_map_file_path_absolute
sync_map_format = self.configuration.os_file_format
parameters = dict()
parameters[gc.PPN_TASK_OS_FILE_SMIL_PAGE_REF] = self.configuration.os_file_smil_page_ref
parameters[gc.PPN_TASK_OS_FILE_SMIL_AUDIO_REF] = self.configuration.os_file_smil_audio_ref
result = self.sync_map.write(sync_map_format, path, parameters)
if not result:
return None
return path
示例10: main
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [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)
#.........这里部分代码省略.........
示例11: test_set_language_on_empty
# 需要导入模块: from aeneas.textfile import TextFile [as 别名]
# 或者: from aeneas.textfile.TextFile import set_language [as 别名]
def test_set_language_on_empty(self):
tfl = TextFile()
self.assertEqual(len(tfl), 0)
tfl.set_language(Language.EN)
self.assertEqual(len(tfl), 0)