Python Convert Wav To Mp3
Solution 1:
I wrote a python library, pydub, that essentially does what Corey's Answer suggests, though it uses ffmpeg in to do the conversions in order to support more formats.
from pydub import AudioSegment
AudioSegment.from_wav("/input/file.wav").export("/output/file.mp3", format="mp3")
Solution 2:
using lame (command line), you can encode wav to mp3 like this:
$ lame --preset insane /path/to/file.wav
which would create:
file.wav.mp3
in Python, you could use subprocess to call it:
wav = 'myfile.wav'
cmd = 'lame --preset insane %s' % wav
subprocess.call(cmd, shell=True)
Solution 3:
You must go for pydub, it is a great module for operations related with audio files.
NOTE. Do remember to install ffmpeg before you use pydub.
For help regarding installation of ffmpeg, you can use this link.
Then to install pydub just open your command prompt and type
pip install pydub
Then to convert any file from wav to mp3 just use pydub as
importpydubsound= pydub.AudioSegment.from_wav("D:/example/apple.wav")
sound.export("D:/example/apple.mp3", format="mp3")
Solution 4:
will you can just rename the file extension , i think os library will help you any way i will give you example :
yourfile.wav ==>> yourfile.mp3 or any type that is for audio and video file
for me it's worked !!
Post a Comment for "Python Convert Wav To Mp3"