示例#1
0
    def _create_syncmap(self, text_map):
        """
        Create a sync map out of the provided interval map,
        and store it in the task object.

        Return a success bool flag.
        """
        self._log("Creating SyncMap")
        self._log("Number of fragments: %d" % len(text_map))
        if len(text_map) != len(self.task.text_file.fragments):
            return False
        try:
            sync_map = SyncMap()
            i = 0
            head = 0
            if self.task.configuration.is_audio_file_head_length != None:
                head = gf.safe_float(self.task.configuration.is_audio_file_head_length, 0)
            for fragment in self.task.text_file.fragments:
                start = head + text_map[i][0]
                end = head + text_map[i][1]
                sync_map_frag = SyncMapFragment(fragment, start, end)
                sync_map.append(sync_map_frag)
                i += 1
            self.task.sync_map = sync_map
            return True
        except:
            return False
示例#2
0
 def load(self, path=None, lines=None):
     syn = SyncMap()
     if path == None:
         path = "res/inputtext/sonnet_parsed.txt"
         lines = 15
     tfl = TextFile(get_abs_path(path), TextFileFormat.PARSED)
     self.assertEqual(len(tfl), lines)
     i = 0
     for fragment in tfl.fragments:
         # dummy time values!
         syn_frag = SyncMapFragment(fragment, i, i + 1)
         syn.append(syn_frag)
         i += 1
     return syn
示例#3
0
文件: test_task.py 项目: cbeer/aeneas
 def dummy_sync_map(self):
     sync_map = SyncMap()
     frag = TextFragment("f001", Language.EN, "Fragment 1")
     sync_map.append(SyncMapFragment(frag, 0, 12.345))
     frag = TextFragment("f002", Language.EN, "Fragment 2")
     sync_map.append(SyncMapFragment(frag, 12.345, 23.456))
     frag = TextFragment("f003", Language.EN, "Fragment 3")
     sync_map.append(SyncMapFragment(frag, 23.456, 34.567))
     return sync_map
示例#4
0
 def dummy_sync_map(self):
     sync_map = SyncMap()
     frag = TextFragment("f001", Language.EN, "Fragment 1")
     sync_map.append(SyncMapFragment(frag, 0, 12.345))
     frag = TextFragment("f002", Language.EN, "Fragment 2")
     sync_map.append(SyncMapFragment(frag, 12.345, 23.456))
     frag = TextFragment("f003", Language.EN, "Fragment 3")
     sync_map.append(SyncMapFragment(frag, 23.456, 34.567))
     return sync_map
示例#5
0
    def _create_syncmap(self, adjusted_map):
        """
        Create a sync map out of the provided interval map,
        and store it in the task object.

        Return a success bool flag.
        """
        self._log("Creating sync map")
        self._log([
            "Number of fragments in adjusted map (including HEAD and TAIL): %d",
            len(adjusted_map)
        ])
        # adjusted map has 2 elements (HEAD and TAIL) more than text_file
        if len(adjusted_map) != len(self.task.text_file.fragments) + 2:
            self._log(
                "The number of sync map fragments does not match the number of text fragments (+2)",
                Logger.CRITICAL)
            return False
        try:
            sync_map = SyncMap()
            head = adjusted_map[0]
            tail = adjusted_map[-1]

            # get language
            language = Language.EN
            self._log(["Language set to default: %s", language])
            if len(self.task.text_file.fragments) > 0:
                language = self.task.text_file.fragments[0].language
                self._log(["Language read from text_file: %s", language])

            # get head/tail format
            head_tail_format = self.task.configuration.os_file_head_tail_format
            # note that str() is necessary, as head_tail_format might be None
            self._log(["Head/tail format: %s", str(head_tail_format)])

            # add head sync map fragment if needed
            if head_tail_format == SyncMapHeadTailFormat.ADD:
                head_frag = TextFragment(u"HEAD", language, [u""])
                sync_map_frag = SyncMapFragment(head_frag, head[0], head[1])
                sync_map.append(sync_map_frag)
                self._log(["Adding head (ADD): %.3f %.3f", head[0], head[1]])

            # stretch first and last fragment timings if needed
            if head_tail_format == SyncMapHeadTailFormat.STRETCH:
                self._log([
                    "Stretching (STRETCH): %.3f => %.3f (head) and %.3f => %.3f (tail)",
                    adjusted_map[1][0], head[0], adjusted_map[-2][1], tail[1]
                ])
                adjusted_map[1][0] = head[0]
                adjusted_map[-2][1] = tail[1]

            i = 1
            for fragment in self.task.text_file.fragments:
                start = adjusted_map[i][0]
                end = adjusted_map[i][1]
                sync_map_frag = SyncMapFragment(fragment, start, end)
                sync_map.append(sync_map_frag)
                i += 1

            # add tail sync map fragment if needed
            if head_tail_format == SyncMapHeadTailFormat.ADD:
                tail_frag = TextFragment(u"TAIL", language, [u""])
                sync_map_frag = SyncMapFragment(tail_frag, tail[0], tail[1])
                sync_map.append(sync_map_frag)
                self._log(["Adding tail (ADD): %.3f %.3f", tail[0], tail[1]])

            self.task.sync_map = sync_map
            self._log("Creating sync map: succeeded")
            return True
        except Exception as e:
            self._log("Creating sync map: failed")
            self._log(["Message: %s", str(e)])
            return False
示例#6
0
    def _create_syncmap(self, adjusted_map):
        """
        Create a sync map out of the provided interval map,
        and store it in the task object.

        Return a success bool flag.
        """
        self._log("Creating sync map")
        self._log(["Number of fragments in adjusted map (including HEAD and TAIL): %d", len(adjusted_map)])
        # adjusted map has 2 elements (HEAD and TAIL) more than text_file
        if len(adjusted_map) != len(self.task.text_file.fragments) + 2:
            self._log("The number of sync map fragments does not match the number of text fragments (+2)", Logger.CRITICAL)
            return False
        try:
            sync_map = SyncMap()
            head = adjusted_map[0]
            tail = adjusted_map[-1]

            # get language
            language = Language.EN
            self._log(["Language set to default: %s", language])
            if len(self.task.text_file.fragments) > 0:
                language = self.task.text_file.fragments[0].language
                self._log(["Language read from text_file: %s", language])

            # get head/tail format
            head_tail_format = self.task.configuration.os_file_head_tail_format
            # note that str() is necessary, as head_tail_format might be None
            self._log(["Head/tail format: %s", str(head_tail_format)])

            # add head sync map fragment if needed
            if head_tail_format == SyncMapHeadTailFormat.ADD:
                head_frag = TextFragment(u"HEAD", language, [u""])
                sync_map_frag = SyncMapFragment(head_frag, head[0], head[1])
                sync_map.append(sync_map_frag)
                self._log(["Adding head (ADD): %.3f %.3f", head[0], head[1]])

            # stretch first and last fragment timings if needed
            if head_tail_format == SyncMapHeadTailFormat.STRETCH:
                self._log(["Stretching (STRETCH): %.3f => %.3f (head) and %.3f => %.3f (tail)", adjusted_map[1][0], head[0], adjusted_map[-2][1], tail[1]])
                adjusted_map[1][0] = head[0]
                adjusted_map[-2][1] = tail[1]

            i = 1
            for fragment in self.task.text_file.fragments:
                start = adjusted_map[i][0]
                end = adjusted_map[i][1]
                sync_map_frag = SyncMapFragment(fragment, start, end)
                sync_map.append(sync_map_frag)
                i += 1

            # add tail sync map fragment if needed
            if head_tail_format == SyncMapHeadTailFormat.ADD:
                tail_frag = TextFragment(u"TAIL", language, [u""])
                sync_map_frag = SyncMapFragment(tail_frag, tail[0], tail[1])
                sync_map.append(sync_map_frag)
                self._log(["Adding tail (ADD): %.3f %.3f", tail[0], tail[1]])

            self.task.sync_map = sync_map
            self._log("Creating sync map: succeeded")
            return True
        except Exception as e:
            self._log("Creating sync map: failed")
            self._log(["Message: %s", str(e)])
            return False