moeseth
moeseth

Reputation: 1945

Python Pydub AudioSegment laggy export

I need to upload AudioSegment object to S3 after doing some editing. What I'm doing is to edit the audio, then export it and then send it to S3.

However, export to mp3 is taking like 2 seconds for 2 minutes song.

So, I'm just wondering if it's possible to send the file to S3 without export it. Note: I see there is raw_data, however, I need to be able to play the saved clip.

Upvotes: 2

Views: 1481

Answers (1)

Jiaaro
Jiaaro

Reputation: 76968

The delay is caused by the transcoding step (converting the raw data to mp3). You can avoid that by exporting WAV files.

A WAV file is essentially just the raw data with some header information at the beginning so exporting with format="wav" will avoid the need to transcode, and should be significantly faster.

However, without any compression, the files will be larger (like 40MB instead of 5MB). You'll probably lose more than 2 seconds due to transferring 5 to 10 times more data over the network.

Some codecs are slower than others, so you may want to experiment with other encodings to strike a different speed/file size balance than mp3 and wav do (or you could try just using regular file compression like gzip, bz2, or a "zip" file on your wav output)

Upvotes: 3

Related Questions