我试图用AudioSegment(pydub)连接两个mp3文件。对于小尺寸文件(小于35 Mb),它可以正常工作。为了更大,我得到一个MemoryError。 Python版本:3.6.2
这是我的代码。谢谢你的帮助!
from pydub import AudioSegment
import eyed3
import os
import gc
import psutil
def make_files(path_to_files, audiofiles):
pre_sermon = AudioSegment.from_mp3("pre_sermon.mp3")
for file_name in audiofiles:
sermon = AudioSegment.from_mp3(path_to_files + file_name)
combined = pre_sermon + sermon
audiofile = eyed3.load(path_to_files + file_name)
combined.export(f'combined/{file_name}', format="mp3", bitrate='128k', tags={'title': audiofile.tag.title,
'artist': audiofile.tag.artist,
'album': audiofile.tag.album,
'comment': audiofile.tag.comments[0].text})
del combined
del sermon
gc.collect()
general_path = 'C:\\projects\\python\\files\\mp3\\sermons\\'
files = set(os.listdir('sermons/'))
combined_files = set(os.listdir('combined/'))
difference = {filename:str(os.stat(os.path.join(general_path, filename)).st_size/1000000) + ' MB' for filename in (files - combined_files)}
print(psutil.virtual_memory())
print(difference)
make_files('sermons/', difference.keys())
答案 0 :(得分:1)
使用64位python解释器解决了这个问题。谢谢嘉罗!