Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioClip.iter_chunks(160) is chunking into [159, 160, 160, ..., 160] #2174

Open
FlyDogDaDa opened this issue May 12, 2024 · 0 comments
Open
Labels
bug Issues that report (apparent) bugs.

Comments

@FlyDogDaDa
Copy link

Expected Behavior

MoviePy: 1.0.3
len(mono_chunk)=160
len(mono_chunk)=160
len(mono_chunk)=160

Actual Behavior

MoviePy: 1.0.3
len(mono_chunk)=159
len(mono_chunk)=160
len(mono_chunk)=160

Steps to Reproduce the Problem

import numpy as np
from moviepy import version
from moviepy.editor import VideoFileClip, AudioClip

print("MoviePy:", version.__version__)


def VAD(original_audio: AudioClip):

    audio = original_audio.copy()  # Copy an audio for local editing
    audio.set_fps(16000)  # Set sampling rate
    chunk_size = 160  # 16000 * 10 // 1000

    i = 0  # Counter used only for testing
    for audio_chunk in original_audio.iter_chunks(chunk_size):
        # Convert to mono 16-bits PCM
        mono_chunk = np.mean(audio_chunk, 1).astype(dtype=np.int16)

        # Print content length
        print(f"{len(mono_chunk)=}")

        if i == 3:  # I only took out 3 for testing.
            break  # stop loop
        i += 1  # Count up the counter


# You can change to other videos. ^_^
video = VideoFileClip(
    "videos\\【spooky's jump scare】 威猛蛾老大要來幫忙打鬼了!!!!! ft. @EvaEmolaCh.mp4"
)
VAD(video.audio)

Specifications

  • Python Version:3.12.3
  • MoviePy Version:1.0.3
  • Platform Name:Windows 11 Pro
  • Platform Version:23H2
@FlyDogDaDa FlyDogDaDa added the bug Issues that report (apparent) bugs. label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

1 participant