我的建议是根据需要使用
pydub.silence.split_on_silence()然后重新组合细分,以使您拥有的文件大小大致与目标大小相同。
就像是
from pydub import AudioSegmentfrom pydub.silence import split_on_silencesound = 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 longtarget_length = 90 * 1000output_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)或者,您可以使用
pydub.silence.detect_nonsilent()查找范围并自行决定在哪里分割原始音频
注意:我也在类似/重复的github问题上发布了此内容



