0

When I do a conversion using ffmpeg, I am able to convert a 3.5MB mp3 file into an ~3.5MB wav file (using ffmpeg -i input.mp3 -acodec pcm_s16le -ac 1 -ar 8000 output.wav). When I use pydub however with the below code

s1 = AudioSegment.from_file("input.mp3", format="mp3")
o1 = s1.export("output.wav",format="wav", parameters=["-acodec","pcm_s16le","-ac","1","-ar","8000"])

the exported wav file is 34.5MB. How can I get pydub to behave as expected?

Dayo
  • 316
  • 4
  • 12
  • If you are converting a 3.5MB `mp3` into a 3.5MB `wav`, something has gone wrong somewhere. The entire point of `mp3` is to compress the raw samples from a `wav` file. – Tom Wyllie Jul 28 '17 at 10:13
  • It seems like you are massively down-sampling the `wav`, your `wav` file has nowhere near the same audio quality as the `mp3`, is this intentional? Beware that byte for byte `mp3` and `wav` are very different... – Tom Wyllie Jul 28 '17 at 10:17
  • @TomWyllie yes, it's intentional to down-sample the output file. I intend to use the audio file with freeswitch. Due to storage and bandwidth restriction, I cannot have each file being that big – Dayo Jul 28 '17 at 10:30
  • If it's possible in your use case, gzipping the wav file after you export will reduce the size considerably – Jiaaro Jul 28 '17 at 11:55
  • although I could not tell from inspecting the code, I don't think pydub supports what I was trying to do. I went ahead and wrote me a helper function to achieve this. – Dayo Jul 28 '17 at 16:19

1 Answers1

0
s1.export("output.mp3", format='mp3', parameters=["-ac","2","-ar","8000"])

The line of code managed to reduce my audio size by half its previous size. Hope this is helpful to someone

Asty
  • 797
  • 1
  • 5
  • 3