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
Expanding split_on_silence with minimum length / file size? #143
Comments
@hclivess My advice is to use something like from pydub import AudioSegment
from pydub.silence import split_on_silence
sound = AudioSegment.from_file("/path/to/file.mp3", format="mp3")
chunks = split_on_silence(
sound,
# split on silences longer than 1000ms (1 sec)
min_silence_len=1000,
# anything under -16 dBFS is considered silence
silence_thresh=-16,
# keep 200 ms of leading/trailing silence
keep_silence=200
)
# now recombine the chunks so that the parts are at least 90 sec long
target_length = 90 * 1000
output_chunks = [chunks[0]]
for chunk in chunks[1:]:
if len(output_chunks[-1]) < target_length:
output_chunks[-1] += chunk
else:
# if the last output chunk is longer than the target length,
# we can start a new one
output_chunks.append(chunk)
# now your have chunks that are bigger than 90 seconds (except, possibly the last one) Alternatively, you can use |
Awesome, thank you very much. I will repost this code to StackExchange if you don't mind |
@hclivess oh, I see the question - will post it there too :) |
Would it be easy/possible to combine minimum chunk length or minimum file size with splitting on silence? I would like to split large files in the silence gaps, but I want the files to be no less than x minutes.
The text was updated successfully, but these errors were encountered: