If I have an MP3 file how can I convert it to a WAV file? (preferably, using a pure python approach)
Install the module pydub
. This is an audio manipulation module for Python. This module can open many multimedia audio and video formats. You can install this module with pip
.
pip install pydub
If you have not installed ffmpeg yet, install it. You can use your package manager to do that.
For Ubuntu / Debian Linux:
apt-get install ffmpeg
When ready, execute the below code:
from os import path
from pydub import AudioSegment
# files
src = "transcript.mp3"
dst = "test.wav"
# convert wav to mp3
sound = AudioSegment.from_mp3(src)
sound.export(dst, format="wav")
Check this link for details.
This is working for me:
import subprocess
subprocess.call(['ffmpeg', '-i', 'audio.mp3',
'audio.wav'])
I maintain an open source library, pydub, which can help you out with that.
from pydub import AudioSegment
sound = AudioSegment.from_mp3("/path/to/file.mp3")
sound.export("/output/path/file.wav", format="wav")
One caveat: it uses ffmpeg to handle audio format conversions (except for wav files, which python handles natively).
note: you probably shouldn't do this conversion on GAE :/ even if it did support ffmpeg. EC2 would be a good match for the job though