AudioSegment results in MemoryError while i have plenty of memory

606 Views Asked by At

I'm trying to concatenate two mp3 files with AudioSegment (pydub). For small size files (less then 35 Mb) it's working. For bigger, i get a MemoryError. Python version:3.6.2

Here is my code. Thank you for any help!

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

1

There are 1 best solutions below

0
On

the problem was solved with a 64-bit python interpreter. Thank you Jiaaro!