Convert mp3 to wav using Python
In this article, we are going to discuss various methods to convert mp3 to wave file format using Python.
First We Need To Install ffmpeg. It Is A Free Open Source Software Project Consist of a Large Suite Of Libraries And Programs For Handling Video, Audio, And Other Multimedia Files.
sudo apt-get install ffmpeg
So First Let Us Install pydub. This is an Audio Manipulation Module. Python Provides a Module Called pydub to Work With Audio Files. pydub is a Python library to work with only .wav files.
sudo apt-get install -y python-pydub
Here you can see there is a python script And hello.mp3 file which converts it into a result.wav file.
The pydub module uses either ffmpeg or avconf programs to do the actual conversion. So you do have to install ffmpeg to make this work. But if you don’t need pydub for anything else, you can just use the built-in subprocess module to call a convertor program like ffmpeg which is shown in the below method.
It is a simple two-line script or code to convert a mp3 file to wav file.
Here we don’t need the pydub module, we can use builtin the subprocess module to call converter program ffmpeg as shown below:
As you can see the wave format is generated.