当我有足够的记忆时,音频片段会产生记忆错误

2024-04-29 00:48:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用AudioSegment(pydub)连接两个mp3文件。对于小文件(小于35MB),它是有效的。更重要的是,我得到了一个记忆错误。 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())

printscreen of error and additional info


Tags: topathnamefromimportostagfiles