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

Improve memory footprint of make_chunks #783

Open
cipherCOM opened this issue Mar 17, 2024 · 0 comments
Open

Improve memory footprint of make_chunks #783

cipherCOM opened this issue Mar 17, 2024 · 0 comments

Comments

@cipherCOM
Copy link

I have a small proposal for the make_chunks function to make a bit more mem aware. What about changing it to a generator expression instead of a list compression. This saved me quite some mem when handling hours of audio data, if I just want to iterate over them to e.g. calculate the RMS.

return [audio_segment[i * chunk_length:(i + 1) * chunk_length]

def make_chunks(audio_segment, chunk_length):
    """
    Breaks an AudioSegment into chunks that are <chunk_length> milliseconds
    long.
    if chunk_length is 50 then you'll get a list of 50 millisecond long audio
    segments back (except the last one, which can be shorter)
    """
    number_of_chunks = ceil(len(audio_segment) / float(chunk_length))
    return (audio_segment[i * chunk_length:(i + 1) * chunk_length]
            for i in range(int(number_of_chunks)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant