Python 音訊檔批次切割
操作
- 安裝 pydub
1.pip3 install pydub - pydub需要依賴 ffmpeg 安裝ffmpeg
1.安裝地址ffmpeg下載連結
2.設定環境變數 - 程式碼實現
from pydub import AudioSegment
from pydub.utils import make_chunks
import os, re
for each in os.listdir("D:/純音樂"):
filename = re.findall(r"(.*?)\.mp3", each)
print(each)
if each:
mp3 = AudioSegment.from_file('D:/純音樂/{}'.format(each), "mp3")
size = 15000
chunks = make_chunks(mp3, size)
for i, chunk in enumerate(chunks):
chunk_name = "{}-{}.mp3".format(each.split(".")[0],i)
print(chunk_name)
chunk.export('D:/純音樂分解/{}'.format(chunk_name), format="mp3")```