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)
Beispiel #2
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
Beispiel #3
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
Beispiel #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 tc_from_string(self, config_string, properties):
     taskconf = TaskConfiguration(config_string)
     for prop, value in properties:
         read_value = taskconf[prop]
         if value is None:
             self.assertIsNone(read_value)
         else:
             self.assertEqual(read_value, value)
 def setter(self, attribute, value, expected):
     taskconf = TaskConfiguration()
     taskconf[attribute] = value
     read_value = taskconf[attribute]
     if expected is None:
         self.assertIsNone(read_value)
     else:
         self.assertEqual(read_value, expected)
 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)
Beispiel #8
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)
 def test_tc_config_string(self):
     taskconf = TaskConfiguration()
     taskconf["language"] = Language.ITA
     taskconf["description"] = u"Test description"
     taskconf["custom_id"] = u"customid"
     taskconf["i_a_head"] = u"20"
     taskconf["i_a_process"] = u"100"
     taskconf["o_format"] = SyncMapFormat.SMIL
     taskconf["o_name"] = u"output.smil"
     taskconf["o_smil_audio_ref"] = u"../audio/audio001.mp3"
     taskconf["o_smil_page_ref"] = u"../text/page001.xhtml"
     expected = u"is_audio_file_head_length=20|is_audio_file_process_length=100|os_task_file_format=smil|os_task_file_name=output.smil|os_task_file_smil_audio_ref=../audio/audio001.mp3|os_task_file_smil_page_ref=../text/page001.xhtml|task_custom_id=customid|task_description=Test description|task_language=ita"
     self.assertEqual(taskconf.config_string, expected)
    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()
Beispiel #11
0
 def test_tc_config_string(self):
     taskconf = TaskConfiguration()
     taskconf.language = Language.IT
     taskconf.description = "Test description"
     taskconf.custom_id = "customid"
     taskconf.is_audio_file_head_length = "20"
     taskconf.is_audio_file_process_length = "100"
     taskconf.os_file_format = SyncMapFormat.SMIL
     taskconf.os_file_name = "output.smil"
     taskconf.os_file_smil_audio_ref = "../audio/audio001.mp3"
     taskconf.os_file_smil_page_ref = "../text/page001.xhtml"
     expected = "task_description=Test description|task_language=it|task_custom_id=customid|is_audio_file_head_length=20|is_audio_file_process_length=100|os_task_file_format=smil|os_task_file_name=output.smil|os_task_file_smil_audio_ref=../audio/audio001.mp3|os_task_file_smil_page_ref=../text/page001.xhtml"
     self.assertEqual(taskconf.config_string(), expected)
 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)
Beispiel #13
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)
Beispiel #14
0
#!/usr/bin/env python
# coding=utf-8

from aeneas.exacttiming import TimeValue
from aeneas.executetask import ExecuteTask
from aeneas.language import Language
from aeneas.syncmap import SyncMapFormat
from aeneas.task import Task
from aeneas.task import TaskConfiguration
from aeneas.textfile import TextFileFormat
import aeneas.globalconstants as gc

# create Task object
config = TaskConfiguration()
# config[gc.PPN_TASK_LANGUAGE] = Language.ENG
config[gc.PPN_TASK_IS_TEXT_FILE_FORMAT] = TextFileFormat.MPLAIN
config[gc.PPN_TASK_OS_FILE_FORMAT] = SyncMapFormat.JSON
task = Task()


def get_align(audio_file, text_file, lang):
    if lang == 'FRA':
        config[gc.PPN_TASK_LANGUAGE] = Language.FRA
    elif lang == 'ARA':
        config[gc.PPN_TASK_LANGUAGE] = Language.ARA
    elif lang == 'DEU':
        config[gc.PPN_TASK_LANGUAGE] = Language.DEU
    elif lang == 'CMN':
        config[gc.PPN_TASK_LANGUAGE] = Language.CMN
    else:
        config[gc.PPN_TASK_LANGUAGE] = Language.ENG
 def test_task_set_configuration(self):
     task = Task()
     taskconf = TaskConfiguration()
     task.configuration = taskconf
     self.assertIsNotNone(task.configuration)
Beispiel #16
0
 def test_task_set_configuration(self):
     task = Task()
     taskconf = TaskConfiguration()
     task.configuration = taskconf
     self.assertNotEqual(task.configuration, None)
Beispiel #17
0
 def tc_from_string(self, config_string, properties):
     taskconf = TaskConfiguration(config_string)
     for prop in properties:
         self.assertEqual(getattr(taskconf, prop[0]), prop[1])
Beispiel #18
0
 def setter(self, attribute, value):
     taskconf = TaskConfiguration()
     setattr(taskconf, attribute, value)
     self.assertEqual(getattr(taskconf, attribute), value)