~ihabunek/vampires

f3f8ebb7efe9f0d3c1b99406aa54c9ed17298805 — Ivan Habunek 4 months ago 7eb4ede
Tweaks
2 files changed, 7 insertions(+), 6 deletions(-)

M index.html
M parse.py
M index.html => index.html +0 -1
@@ 67,7 67,6 @@
  </body>

  <script type="text/javascript">
    // TODO: timings need tweaking
    const slideTimings = {
      "slides/slide_01.jpg": 0.0,
      "slides/slide_02.jpg": 25.9,

M parse.py => parse.py +7 -5
@@ 39,12 39,12 @@ def _extract_audio_segments(root):
            count = 0


def _expand_audio_segments(root):
def _expand_audio_segments(segments):
    """Join segments of 7 frames or smaller into the previous segment"""
    buffer = None
    buffer_count = 0

    for data, count in _extract_audio_segments(root):
    for data, count in segments:
        if buffer and count > 7:
            yield buffer, buffer_count
            buffer = data


@@ 64,19 64,21 @@ def extract_segmented_audio(root):
    if not os.path.isdir("audio"):
        os.mkdir("audio")

    segments = _extract_audio_segments(root)
    segments = _expand_audio_segments(segments)

    total = 0
    all_data = b""
    for index, (data, count) in enumerate(_expand_audio_segments(root)):
    for index, (data, count) in enumerate(segments):
        all_data += data
        minutes = int((total / 7) / 60)
        seconds = int(total / 7) - minutes * 60
        time = f"{minutes:0>2}:{seconds:0>2}"
        print(f"Audio chunk @ {time} - {count} frames - {total} total")
        total += count
        print(f"Audio chunk @ {time} - {count} frames")

        # # Uncomment to save individual audio chunks
        # filename = f"audio/{index:0>2}_{time}_{count}.mp3"
        # print(filename)
        # with open(filename, "wb") as f:
        #     f.write(data)