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


Python textfile.TextFile类代码示例

本文整理汇总了Python中aeneas.textfile.TextFile的典型用法代码示例。如果您正苦于以下问题:Python TextFile类的具体用法?Python TextFile怎么用?Python TextFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: check_espeak

    def check_espeak(cls):
        """
        Check whether ``espeak`` can be called.

        Return ``True`` on failure and ``False`` on success.

        :rtype: bool
        """
        try:
            from aeneas.textfile import TextFile
            from aeneas.textfile import TextFragment
            from aeneas.ttswrappers.espeakttswrapper import ESPEAKTTSWrapper
            text = u"From fairest creatures we desire increase,"
            text_file = TextFile()
            text_file.add_fragment(TextFragment(language=u"eng", lines=[text], filtered_lines=[text]))
            handler, output_file_path = gf.tmp_file(suffix=u".wav")
            ESPEAKTTSWrapper().synthesize_multiple(text_file, output_file_path)
            gf.delete_file(handler, output_file_path)
            gf.print_success(u"espeak         OK")
            return False
        except:
            pass
        gf.print_error(u"espeak         ERROR")
        gf.print_info(u"  Please make sure you have espeak installed correctly")
        gf.print_info(u"  and that its path is in your PATH environment variable")
        gf.print_info(u"  You might also want to check that the espeak-data directory")
        gf.print_info(u"  is set up correctly, for example, it has the correct permissions")
        return True
开发者ID:danielbair,项目名称:aeneas,代码行数:28,代码来源:diagnostics.py

示例2: main

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)
开发者ID:cambell-prince,项目名称:aeneas,代码行数:25,代码来源:read_text.py

示例3: test_synthesize

 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)
开发者ID:cbeer,项目名称:aeneas,代码行数:8,代码来源:test_synthesizer.py

示例4: test_synthesize_with_unicode

 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)
开发者ID:cbeer,项目名称:aeneas,代码行数:8,代码来源:test_synthesizer.py

示例5: perform

 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
开发者ID:cambell-prince,项目名称:aeneas,代码行数:8,代码来源:test_synthesizer.py

示例6: test_set_language

 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)
开发者ID:cbeer,项目名称:aeneas,代码行数:9,代码来源:test_textfile.py

示例7: test_read_from_list

 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)
开发者ID:cbeer,项目名称:aeneas,代码行数:11,代码来源:test_textfile.py

示例8: test_read_from_list_with_ids

 def test_read_from_list_with_ids(self):
     tfl = TextFile()
     text_list = [
         ["a1", "fragment 1"],
         ["b2", "fragment 2"],
         ["c3", "fragment 3"],
         ["d4", "fragment 4"],
         ["e5", "fragment 5"]
     ]
     tfl.read_from_list_with_ids(text_list)
     self.assertEqual(len(tfl), 5)
开发者ID:cbeer,项目名称:aeneas,代码行数:11,代码来源:test_textfile.py

示例9: inner

 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)
开发者ID:ptrwtts,项目名称:aeneas,代码行数:12,代码来源:test_synthesizer.py

示例10: test_read_from_list_with_ids

 def test_read_from_list_with_ids(self):
     tfl = TextFile()
     text_list = [
         (u"a1", u"fragment 1"),
         (u"b2", u"fragment 2"),
         (u"c3", u"fragment 3"),
         (u"d4", u"fragment 4"),
         (u"e5", u"fragment 5")
     ]
     tfl.read_from_list_with_ids(text_list)
     self.assertEqual(len(tfl), 5)
     self.assertEqual(tfl.chars, 50)
开发者ID:ptrwtts,项目名称:aeneas,代码行数:12,代码来源:test_textfile.py

示例11: get_text_file

 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
开发者ID:eomerdws,项目名称:aeneas,代码行数:15,代码来源:abstract_cli_program.py

示例12: _populate_text_file

 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")
开发者ID:ptrwtts,项目名称:aeneas,代码行数:33,代码来源:task.py

示例13: test_append_fragment_multiple

 def test_append_fragment_multiple(self):
     tfl = TextFile()
     self.assertEqual(len(tfl), 0)
     tfl.append_fragment(TextFragment("a1", Language.EN, "fragment 1"))
     self.assertEqual(len(tfl), 1)
     tfl.append_fragment(TextFragment("a2", Language.EN, "fragment 2"))
     self.assertEqual(len(tfl), 2)
     tfl.append_fragment(TextFragment("a3", Language.EN, "fragment 3"))
     self.assertEqual(len(tfl), 3)
开发者ID:fduch2k,项目名称:aeneas,代码行数:9,代码来源:test_textfile.py

示例14: test_add_fragment_multiple

 def test_add_fragment_multiple(self):
     tfl = TextFile()
     self.assertEqual(len(tfl), 0)
     tfl.add_fragment(TextFragment(u"a1", Language.ENG, [u"fragment 1"]))
     self.assertEqual(len(tfl), 1)
     tfl.add_fragment(TextFragment(u"a2", Language.ENG, [u"fragment 2"]))
     self.assertEqual(len(tfl), 2)
     tfl.add_fragment(TextFragment(u"a3", Language.ENG, [u"fragment 3"]))
     self.assertEqual(len(tfl), 3)
     self.assertEqual(tfl.chars, 30)
开发者ID:ptrwtts,项目名称:aeneas,代码行数:10,代码来源:test_textfile.py

示例15: _populate_text_file

 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)
开发者ID:cambell-prince,项目名称:aeneas,代码行数:18,代码来源:task.py


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