我想使用pyDub將單個單詞(以及兩者之間的靜音)的長WAV文件作爲輸入,然後去除所有沉默,並輸出剩餘的塊個人WAV文件。文件名可以是連續的數字,如001.wav,002.wav,003.wav等。使用pyDub砍掉一個長音頻文件
Github頁面上的「Yet another Example?」示例做了非常類似的事情,但它不是輸出單獨的文件,而是將沉默剝段回一起到一個文件:
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文件?如果是這樣,怎麼樣?
謝謝!
感謝您的回覆,但我有點初學者,但我仍然不知道如何處理傳球將音頻片段轉換爲導出方法。 – user3643227