2

我正在尝试将两个 mp3 文件与 AudioSegment (pydub) 连接起来。对于小尺寸文件(小于 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())

错误和附加信息的打印屏幕

4

1 回答 1

3

使用 64 位 python 解释器解决了这个问题。谢谢嘉罗!

于 2018-01-18T07:52:20.437 回答