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.

ffmpeg download

  • 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.

Convert mp3 to wav by FFmpeg

  • Now go to C Drive and make a folder & name it PATH_program.
  • Paste all the content in that PATH_program.

PATH_program

  • You will copy the path of this PATH_program folder.

PATH_program

  • 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.

installed FFmpeg

  • 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:

ffmpeg

The converted audio will be saved automatically, the folders will look like the following picture.

installed FFmpeg

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:

Convert .Mp3 to .Wav By PyDub

 

Leave a Reply

Your email address will not be published. Required fields are marked *