首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我有足够的内存时,AudioSegment会导致MemoryError

当我有足够的内存时,AudioSegment会导致MemoryError
EN

Stack Overflow用户
提问于 2018-01-15 16:44:39
回答 1查看 423关注 0票数 2

我正在尝试用AudioSegment (pydub)连接两个mp3文件。对于小文件(小于35Mb),它可以工作。对于更大的,我会得到一个MemoryError。Python版本:3.6.2

这是我的代码。谢谢你的帮助!

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2018-01-18 15:52:20

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48259461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档