我想使用 pyDub 将单个单词的长 WAV 文件(以及中间的静音)作为输入,然后去掉所有的静音,并输出剩余的块是单独的 WAV 文件。文件名可以只是序号,如 001.wav、002.wav、003.wav 等。
Github 页面上的“又一个示例? ”示例做了非常相似的事情,但它不是输出单独的文件,而是将静音剥离的片段组合回一个文件中:
from pydub import AudioSegment
from pydub.utils import db_to_float
# Let's load up the audio we need...
podcast = AudioSegment.from_mp3("podcast.mp3")
intro = AudioSegment.from_wav("intro.wav")
outro = AudioSegment.from_wav("outro.wav")
# Let's consider anything that is 30 decibels quieter than
# the average volume of the podcast to be silence
average_loudness = podcast.rms
silence_threshold = average_loudness * db_to_float(-30)
# filter out the silence
podcast_parts = (ms for ms in podcast if ms.rms > silence_threshold)
# combine all the chunks back together
podcast = reduce(lambda a, b: a + b, podcast_parts)
# add on the bumpers
podcast = intro + podcast + outro
# save the result
podcast.export("podcast_processed.mp3", format="mp3")
是否可以将这些 podcast_parts 片段输出为单独的 WAV 文件?如果是这样,怎么做?
谢谢!