How to convert Mp3 to wav in Python
In this post, we will learn how we convert MP3 to WAV in Python. Now, When converting MP3s to WAVs, why do we need to do this? The main reason for converting the MP3 file to a WAV file is that WAV files are high-quality files in an uncompressed form, which helps record in the studio and master audio.
You can check: Find the duration of a WAV file in Python
Converting by FFmpeg:
We first have to install FFmpeg which is a python library. This library handles video, audio, and other multimedia files. to install it follow the below-given command:
pip install ffmpeg-python
We will have to install FFmpeg to our system to complete the conversion. Follow the steps to install FFmpeg to the system.
- Go to FFmpeg’s website and download the full version of FFmpeg. Click Here.
- Let the zip file download and unzip it to a specified folder of your choice.
- Go to the bin folder and extract all the files from the folder.
- Now go to C Drive and make a folder & name it PATH_program.
- Paste all the content in that PATH_program.
- You will copy the path of this PATH_program folder.
- Add the path to the system’s Environment.
- If you want to check your steps, write FFmpeg in your cmd or terminal.
- If the output matches the steps given below, then you have installed FFmpeg properly.
- You are all set to write code.
CODE:
# import modules import subprocess # converting mp3 to wav file subprocess.call(['ffmpeg', '-i', 'audio.mp3', 'converted_to_wav_file.wav'])
Output:
The converted audio will be saved automatically, the folders will look like the following picture.
Convert .Mp3 to .Wav By PyDub
Our second approach will be from PyDub which is a library in Python for audio altering and editing. You will have to install PyDub into your system by running the following command.
pip install pydub
Code:
# import the modules from os import path from pydub import AudioSegment input = "audio.mp3" output = "audio_in_wav.wav" #conversion audio = AudioSegment.from_mp3(input) audio.export(output, format="wav")
Output:
Leave a Reply