Is there a way to convert a media object to an mp3?

What I’m trying to do:
I’m trying to implement the audio recording functionality into my app. For example, in the example below, is there a way to turn the audio.obj to a .mp3 file? I’d like to turn any audio file that I upload immediately into an mp3.

What I’ve tried and what’s not working:
I’ve tried googling, and didn’t see anything.

Code Sample:


**Clone link:**
*share a copy of your app*

I’m guessing, and hoping, that the .obj extension is coming from something weird like a browser. I see on the MIME type that it’s a audio/webm. So in that case you could use pydub, which is available in a full Python server module. Link to pydub.

Here is some sample code, but I have no idea if it will work in your case. Really depends on what format that audio is in.

from pydub import AudioSegment

song = AudioSegment.from_file(audio.obj,"webm")
song.export("audio.mp3", format="mp3", bitrate="320k")
2 Likes