Пример #1
0
def extract(input, subtitle):
    start = time_to_millis(subtitle.start) - 100
    end = time_to_millis(subtitle.end) + 400

    print(subtitle.text + " " + str(start) + " to " + str(end))

    cut = song[start:end]
    cut.export("out/" + subtitle.text + "_" + str(subtitle.index) + ".mp3",
               format="mp3")
Пример #2
0
def print_segment(seg):
    print(seg[0].start)

    for sub in seg:
        print(sub.text)

    print(seg[-1].end)
    print("------------------------------------")
    print("Segment duration: " +
          str((time_to_millis(seg[-1].end) - time_to_millis(seg[0].start)) /
              1000))
    print("====================================")
Пример #3
0
def get_segments(subtitles):
    segments = []

    prev_end = -1000000
    curr_segment = None

    for subtitle in subtitles:
        this_start = time_to_millis(subtitle.start)
        if this_start - prev_end > FIVE_SECONDS:
            if curr_segment != None:
                segments.append(curr_segment)
            curr_segment = []

        curr_segment.append(subtitle)

        prev_end = time_to_millis(subtitle.end)

    # append last segment
    segments.append(curr_segment)

    return segments
Пример #4
0
    print(seg[-1].end)
    print("------------------------------------")
    print("Segment duration: " +
          str((time_to_millis(seg[-1].end) - time_to_millis(seg[0].start)) /
              1000))
    print("====================================")


audio_filename = sys.argv[1]
subtitle_filename = sys.argv[2]

subtitles = parser.parse(subtitle_filename)
segments = get_segments(subtitles)

song = AudioSegment.from_mp3(audio_filename)

folder = "out/"
episode = "e01"
n = 1
for seg in segments:
    start = time_to_millis(seg[0].start) - 1000
    end = time_to_millis(seg[-1].end) + 1500

    cut = song[start:end]
    cut.export(folder + episode + "_seg" + str(n) + ".mp3", format="mp3")

    print("===== Segment " + str(n) + " ========")
    print_segment(seg)

    n += 1
Пример #5
0
 def duration(self) -> int:
     return time_to_millis(self.end) - time_to_millis(self.start)