コード例 #1
0
def transcription():
    transcription = Transcription()
    transcription.add_edge(3, 5, speech="hi there, I'm Penny",
                           speaker='Penny')
    transcription.add_edge(5, 5.5)
    transcription.add_edge(5.5, 7, speech="hi. I'm Leonard", speaker='Leonard')

    transcription.add_edge(T('A'), T('B'), summary='Leonard meets Penny')

    transcription.add_edge(7, T('C'))

    return transcription
コード例 #2
0
ファイル: srt.py プロジェクト: buddhashrestha/thesis
    def _duration(self, lines, start, end):
        """Iterate dialogue lines + (estimated) timeranges"""

        if self.duration:
            length = np.array([len(line)+1 for line in lines])
            ratio = 1. * np.cumsum(length) / np.sum(length)
            end_times = start + (end - start) * ratio
        else:
            end_times = [T() for line in lines[:-1]] + [end]

        start_time = start
        for line, end_time in six.moves.zip(lines, end_times):
            yield line, start_time, end_time
            start_time = end_time
コード例 #3
0
    def read(self, path, **kwargs):

        T.reset()
        transcription = Transcription()

        previousNode = TStart

        arc = []

        for line in self.iterlines(path, encoding='utf-8'):

            # skip comments
            if re.search(r'^;;', line):
                continue

            fields = line.strip().split()

            # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            word = fields[4]

            # remove punctuations
            if not self.punctuation:
                word = re.sub(r'[\.!,;?":]+', ' ', word)
                word = re.sub(r' +', ' ', word)

            word = word.strip()
            if not word:
                continue

            # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            confidence = float(fields[5])

            start_time = round(float(fields[2]), 3)
            duration = round(float(fields[3]), 3)
            end_time = float(start_time)+float(duration)
            end_time = round(end_time, 3)

            if duration == 0:
                node_start = previousNode
                node_end = T()

                if len(arc) == 2:

                    transcription.remove_edge(arc[0], arc[1])
                    transcription.add_edge(arc[0], node_end, **arc_data)
                    node_inter = T()
                    transcription.add_edge(node_end, node_inter, speech=word, confidence=confidence)
                    transcription.add_edge(node_inter, arc[1])
                    arc.append(node_end)
                    arc.append(node_inter)
                    node_end=arc[1]

                elif len(arc) > 2:
                    node_anc_start = arc[0]
                    node_anc_end = arc[1]
                    transcription.remove_edge(arc[len(arc)-1], node_anc_end)
                    transcription.add_edge(arc[len(arc)-1], node_end, speech=word, confidence=confidence)
                    transcription.add_edge(node_end, node_anc_end)
                    arc.append(node_end)
                    node_end=arc[1]

            else:
                addEdge = True
                node_start = T(start_time)
                node_end = T(end_time)
                if previousNode.drifting:
                    if not transcription.has_edge(previousNode, node_start):
                        transcription.add_edge(previousNode, node_start)
                else:
                    if node_start < previousNode:
                        node_start = previousNode
                    elif node_start > previousNode:
                        transcription.add_edge(previousNode, node_start)
                if node_start.anchored and node_end.anchored:
                    if node_start == node_end:
                        addEdge = False
                        node_start = previousNode
                        node_end = T()
                        if len(arc) == 2:
                            transcription.remove_edge(arc[0], arc[1])
                            transcription.add_edge(arc[0], node_end, **arc_data)
                            node_inter = T()
                            transcription.add_edge(node_end, node_inter,
                                                   speech=word,
                                                   confidence=confidence)
                            transcription.add_edge(node_inter, arc[1])
                            arc.append(node_end)
                            arc.append(node_inter)
                            node_end = arc[1]
                        elif len(arc) > 2:
                            node_anc_start = arc[0]
                            node_anc_end = arc[1]
                            transcription.remove_edge(arc[len(arc) - 1],
                                                      node_anc_end)
                            transcription.add_edge(arc[len(arc) - 1], node_end, speech=word, confidence=confidence)
                            transcription.add_edge(node_end, node_anc_end)
                            arc.append(node_end)
                            node_end = arc[1]
                    else:
                        arc = [node_start, node_end]
                        arc_data = {'speech': word, 'confidence': confidence}
                if addEdge:
                    transcription.add_edge(node_start, node_end,
                                           speech=word, confidence=confidence)
            previousNode = node_end

        transcription.add_edge(previousNode, TEnd)

        self._loaded = transcription

        return self