Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python library for converting files to MP3 and setting their quality

Tags:

I'm trying to find a Python library that would take an audio file (e.g. .ogg, .wav) and convert it into mp3 for playback on a webpage.

Also, any thoughts on setting its quality for playback would be great.

Thank you.

like image 401
Abid A Avatar asked Aug 07 '09 17:08

Abid A


People also ask

What is the name of the library used to play mp3 files in Python?

Play Mp3 Files With Python Using the playsound Package One simple way to play an mp3 file using Python is with the help of playsound library. It can be used to play both . mp3 and . wav files.


1 Answers

I wrote a library designed to do that =D

from pydub import AudioSegment
AudioSegment.from_file("/input/file").export("/output/file", format="mp3")

Easy!

to specify a bitrate, just use the bitrate kwarg…

from pydub import AudioSegment
sound = AudioSegment.from_file("/input/file")
sound.export("/output/file", format="mp3", bitrate="128k")
like image 133
Jiaaro Avatar answered Sep 30 '22 04:09

Jiaaro