Suppose I have two audio segments of the same sample rate that I have imported from .wav files in Pydub, and assume I know which is shorter. Now suppose I want to split the longer audio file into two segments so that the first segment is the exact same length (down to the exact same number of samples!) as the shorter audio file and assign each of these two segments to new audio segments. How can I do this in Pydub? If I cannot get this level of precision using Pydub, can you give me an alternative that will work just as well?
Basically I just want to split the longer audio segment into two at the sample-perfect level. Here's an illustration of what I want:
AudioSegment (pydubseg, name) Bases: object. This class is a wrapper for a pydub. AudioSegment that provides additional methods. auditory_scene_analysis (debug=False, debugplot=False)
open() This function opens a file to read/write audio data. The function needs two parameters - first the file name and second the mode. The mode can be 'wb' for writing audio data or 'rb' for reading.
You can use AudioSegment().get_array_of_samples() and then construct new segments with the precise number of samples you want:
samples = sound.get_array_of_samples()
shorter = sound._spawn(samples[:20000])
Note: this code is not tested - I wrote it on my iPhone :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With