Instantiate AudioSegment in from_file, instead of using _from_safe_wav #490
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I previously made a pull request (#453) which failed under Python 2.7. After thinking about it some more, I also realized that using a bytearray changed things in a pretty major way by making AudioSegments mutable. So I went back to the drawing board. The graphs in #453 still apply, so I won't repeat them here, but here are some new ones from the Fil memory profiler.
Prior to the change (pydub at master):
And after the change:
This is the memory usage of opening a 57MB MP3 file using
from_file
and changing the sample rate to 16000.The only change to pydub is replacing the call to
_from_safe_wav
with an instantiation of the class directly. Since_from_safe_wav
just reads the BytesIO object and instantiates the class using the bytes, this should be exactly the same as before in every way, except with fewer copies of the data getting made.Thank you for your time!