示例#1
0
def align_audio(
        language: LanguageEnum = Form(...),
        text_file_format: TextFileFormatEnum = Form(...),
        transcript: UploadFile = File(...),
        audio: UploadFile = File(...),
):
    try:
        # prepare config
        aeneas_config = TaskConfiguration()
        aeneas_config[gc.PPN_TASK_IS_TEXT_FILE_FORMAT] = text_file_format
        aeneas_config[gc.PPN_TASK_LANGUAGE] = language

        # get named temporary files
        tmp_audio = convert_to_tempfile(audio)
        tmp_transcript = convert_to_tempfile(transcript)

        # create task
        task = Task()
        task.configuration = aeneas_config
        task.audio_file_path_absolute = Path(tmp_audio.name)
        task.text_file_path_absolute = Path(tmp_transcript.name)

        # process Task
        ExecuteTask(task).execute()

        tmp_audio.close()
        tmp_transcript.close()

        return [(str(fragment.begin), str(fragment.end), fragment.text)
                for fragment in task.sync_map_leaves() if fragment.is_regular]
    except Exception as e:
        raise HTTPException(status_code=500,
                            detail="Error during processing: " + str(e)) from e
示例#2
0
 def test_task_sync_map_leaves(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration["language"] = Language.ENG
     task.configuration["o_format"] = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     self.assertEqual(len(task.sync_map_leaves()), 3)
示例#3
0
def align_files_in_place(data: InputDataFiles):
    try:
        # prepare config
        aeneas_config = TaskConfiguration()
        aeneas_config[gc.PPN_TASK_IS_TEXT_FILE_FORMAT] = data.text_file_format
        aeneas_config[gc.PPN_TASK_LANGUAGE] = data.language

        # create task
        task = Task()
        task.configuration = aeneas_config
        task.audio_file_path_absolute = Path(data.audio_filename)
        task.text_file_path_absolute = Path(data.transcript_filename)

        # process Task
        ExecuteTask(task).execute()

        with open(data.alignment_filename, "w") as f:
            f.write(
                orjson.dumps([(str(fragment.begin), str(fragment.end),
                               fragment.text)
                              for fragment in task.sync_map_leaves()
                              if fragment.is_regular]).decode())
    except Exception as e:
        raise HTTPException(status_code=500,
                            detail="Error during processing: " + str(e)) from e
示例#4
0
def createSyncedLyricsFile(lyrics, file):
    global lyricsSynced, errors
    f = open("tempSync.txt", "w+")
    f.write(lyrics)
    f.close()
    config = TaskConfiguration()
    config[gc.PPN_TASK_LANGUAGE] = Language.FRA
    config[gc.PPN_TASK_IS_TEXT_FILE_FORMAT] = TextFileFormat.PLAIN
    config[gc.PPN_TASK_OS_FILE_FORMAT] = SyncMapFormat.AUDH
    task = Task()
    task.configuration = config
    try:
        task.audio_file_path_absolute = file
        task.text_file_path_absolute = "tempSync.txt"
        ExecuteTask(task).execute()
        syncedLyricsFile = open(file[:-4] + ".lrc", "w+")
        for fragment in task.sync_map_leaves():
            syncedLyricsFile.write(
                str('[' + gf.time_to_hhmmssmmm(fragment.interval.begin, '.')[3:-1] + ']' + fragment.text + '\n'))
        syncedLyricsFile.close()
        print("   Sync Added", sep=' ', end='', flush=True)
        lyricsSynced += 1
    except Exception as e :
        errors += 1
        print("   Sync error", sep=' ', end='',flush=True)
 def test_task_sync_map_leaves(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration["language"] = Language.ENG
     task.configuration["o_format"] = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     self.assertEqual(len(task.sync_map_leaves()), 3)
示例#6
0
文件: test_task.py 项目: cbeer/aeneas
 def test_set_text_file_path_absolute_05(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.is_text_file_format = TextFileFormat.PARSED
     task.text_file_path_absolute = get_abs_path("res/inputtext/sonnet_parsed.txt")
     self.assertNotEqual(task.text_file, None)
     self.assertEqual(len(task.text_file), 15)
示例#7
0
文件: test_task.py 项目: cbeer/aeneas
 def test_set_text_file_path_absolute_03(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.is_text_file_format = TextFileFormat.UNPARSED
     task.configuration.is_text_unparsed_class_regex = "ra"
     task.configuration.is_text_unparsed_id_sort = IDSortingAlgorithm.NUMERIC
     task.text_file_path_absolute = get_abs_path("res/inputtext/sonnet_unparsed_class_id.xhtml")
     self.assertNotEqual(task.text_file, None)
     self.assertEqual(len(task.text_file), 15)
示例#8
0
文件: test_task.py 项目: cbeer/aeneas
 def test_output_sync_map_03(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.os_file_format = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     output_path = tempfile.mkdtemp()
     path = task.output_sync_map_file(container_root_path=output_path)
     self.assertEqual(path, None)
     shutil.rmtree(output_path)
示例#9
0
 def test_output_sync_map(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.os_file_format = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     handler, output_file_path = tempfile.mkstemp(suffix=".txt")
     task.sync_map_file_path_absolute = output_file_path
     path = task.output_sync_map_file()
     self.assertNotEqual(path, None)
     self.assertEqual(path, output_file_path)
     delete_file(handler, output_file_path)
示例#10
0
 def test_output_sync_map(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration["language"] = Language.ENG
     task.configuration["o_format"] = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     handler, output_file_path = gf.tmp_file(suffix=".txt")
     task.sync_map_file_path_absolute = output_file_path
     path = task.output_sync_map_file()
     self.assertIsNotNone(path)
     self.assertEqual(path, output_file_path)
     gf.delete_file(handler, output_file_path)
示例#11
0
 def test_output_sync_map(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.os_file_format = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     handler, output_file_path = tempfile.mkstemp(suffix=".txt")
     task.sync_map_file_path_absolute = output_file_path
     path = task.output_sync_map_file()
     self.assertNotEqual(path, None)
     self.assertEqual(path, output_file_path)
     delete_file(handler, output_file_path)
示例#12
0
 def test_output_sync_map(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration["language"] = Language.ENG
     task.configuration["o_format"] = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     handler, output_file_path = gf.tmp_file(suffix=".txt")
     task.sync_map_file_path_absolute = output_file_path
     path = task.output_sync_map_file()
     self.assertIsNotNone(path)
     self.assertEqual(path, output_file_path)
     gf.delete_file(handler, output_file_path)
示例#13
0
文件: test_task.py 项目: cbeer/aeneas
 def test_output_sync_map_06(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.os_file_format = SyncMapFormat.SMIL
     task.configuration.os_file_smil_page_ref = "Text/page.xhtml"
     task.sync_map = self.dummy_sync_map()
     handler, output_file_path = tempfile.mkstemp(suffix=".smil")
     task.sync_map_file_path_absolute = output_file_path
     path = task.output_sync_map_file()
     self.assertEqual(path, None)
     os.close(handler)
     os.remove(output_file_path)
    def align_audio_and_text(self, file_path):
        config = TaskConfiguration()
        config[gc.PPN_TASK_LANGUAGE] = Language.PAN
        config[gc.PPN_TASK_IS_TEXT_FILE_FORMAT] = TextFileFormat.PLAIN
        config[gc.PPN_TASK_OS_FILE_FORMAT] = SyncMapFormat.JSON
        task = Task()
        task.configuration = config

        task.audio_file_path_absolute = self.audio_file_path
        task.text_file_path_absolute = self.txt_file_path
        task.sync_map_file_path_absolute = file_path
        ExecuteTask(task).execute()
        task.output_sync_map_file()
示例#15
0
 def set_text_file(self, path, fmt, expected, id_regex=None, class_regex=None, id_sort=None):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration["language"] = Language.ENG
     task.configuration["i_t_format"] = fmt
     if class_regex is not None:
         task.configuration["i_t_unparsed_class_regex"] = class_regex
     if id_regex is not None:
         task.configuration["i_t_unparsed_id_regex"] = id_regex
     if id_sort is not None:
         task.configuration["i_t_unparsed_id_sort"] = id_sort
     task.text_file_path_absolute = gf.absolute_path(path, __file__)
     self.assertIsNotNone(task.text_file)
     self.assertEqual(len(task.text_file), expected)
示例#16
0
 def set_text_file(self, path, fmt, expected, id_regex=None, class_regex=None, id_sort=None):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.is_text_file_format = fmt
     if id_regex is not None:
         task.configuration.is_text_unparsed_id_regex = id_regex
     if class_regex is not None:
         task.configuration.is_text_unparsed_class_regex = class_regex
     if id_sort is not None:
         task.configuration.is_text_unparsed_id_sort = id_sort
     task.text_file_path_absolute = get_abs_path(path)
     self.assertNotEqual(task.text_file, None)
     self.assertEqual(len(task.text_file), expected)
示例#17
0
文件: test_task.py 项目: cbeer/aeneas
 def test_output_sync_map_02(self):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.os_file_format = SyncMapFormat.TXT
     task.sync_map = self.dummy_sync_map()
     handler, output_file_path = tempfile.mkstemp(suffix=".txt")
     task.sync_map_file_path = output_file_path
     output_path = tempfile.mkdtemp()
     path = task.output_sync_map_file(container_root_path=output_path)
     self.assertNotEqual(path, None)
     self.assertEqual(path, os.path.join(output_path, output_file_path))
     os.close(handler)
     os.remove(output_file_path)
     shutil.rmtree(output_path)
示例#18
0
 def set_text_file(self,
                   path,
                   fmt,
                   expected,
                   id_regex=None,
                   class_regex=None,
                   id_sort=None):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration.language = Language.EN
     task.configuration.is_text_file_format = fmt
     if id_regex is not None:
         task.configuration.is_text_unparsed_id_regex = id_regex
     if class_regex is not None:
         task.configuration.is_text_unparsed_class_regex = class_regex
     if id_sort is not None:
         task.configuration.is_text_unparsed_id_sort = id_sort
     task.text_file_path_absolute = get_abs_path(path)
     self.assertNotEqual(task.text_file, None)
     self.assertEqual(len(task.text_file), expected)
示例#19
0
 def set_text_file(self,
                   path,
                   fmt,
                   expected,
                   id_regex=None,
                   class_regex=None,
                   id_sort=None):
     task = Task()
     task.configuration = TaskConfiguration()
     task.configuration["language"] = Language.ENG
     task.configuration["i_t_format"] = fmt
     if class_regex is not None:
         task.configuration["i_t_unparsed_class_regex"] = class_regex
     if id_regex is not None:
         task.configuration["i_t_unparsed_id_regex"] = id_regex
     if id_sort is not None:
         task.configuration["i_t_unparsed_id_sort"] = id_sort
     task.text_file_path_absolute = gf.absolute_path(path, __file__)
     self.assertIsNotNone(task.text_file)
     self.assertEqual(len(task.text_file), expected)
示例#20
0
 def test_task_set_configuration(self):
     task = Task()
     taskconf = TaskConfiguration()
     task.configuration = taskconf
     self.assertIsNotNone(task.configuration)
示例#21
0
 def test_task_set_configuration(self):
     task = Task()
     taskconf = TaskConfiguration()
     task.configuration = taskconf
     self.assertNotEqual(task.configuration, None)
示例#22
0
 def test_task_set_configuration(self):
     task = Task()
     taskconf = TaskConfiguration()
     task.configuration = taskconf
     self.assertIsNotNone(task.configuration)
示例#23
0
文件: test_task.py 项目: cbeer/aeneas
 def test_set_configuration(self):
     task = Task()
     taskconf = TaskConfiguration()
     task.configuration = taskconf
     self.assertNotEqual(task.configuration, None)