它真正的简单易用的pydub模块,其详细信息在此处和此处
pydub有一个make_chunks您可以chunk length在中指定的方法milliseconds。
make_chunks(your_audio_file_object, chunk_length_ms)
这是将wav文件拆分为一秒的工作代码。我有一个8.5秒的文件,所以程序创建了9个1秒的块playable。最后一块将较小,具体取决于音频持续时间。
from pydub import AudioSegmentfrom pydub.utils import make_chunksmyaudio = AudioSegment.from_file("myAudio.wav" , "wav") chunk_length_ms = 1000 # pydub calculates in millisecchunks = make_chunks(myaudio, chunk_length_ms) #Make chunks of one sec#Export all of the individual chunks as wav filesfor i, chunk in enumerate(chunks): chunk_name = "chunk{0}.wav".format(i) print "exporting", chunk_name chunk.export(chunk_name, format="wav")
输出量
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32Type "copyright", "credits" or "license()" for more information.>>> ================================ RESTART ================================>>> exporting chunk0.wavexporting chunk1.wavexporting chunk2.wavexporting chunk3.wavexporting chunk4.wavexporting chunk5.wavexporting chunk6.wavexporting chunk7.wavexporting chunk8.wav>>>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)