问题
If I have an MP3 file how can I convert it to a WAV file? (preferably, using a pure python approach)
回答1:
In a comment on sbery2A's answer, you said you want to put an MP3 decoding feature into Google App Engine.
Your only possible hope is to use Python to send the MP3 data to another server, and do the MP3 decode on that server, and then send the decoded data back to the App Engine server. Google isn't going to let you put heavy load on the CPUs of the App Engine servers by doing the MP3 decode actually on the server. Google also prevents you from running any C code; see the App Engine FAQ. You aren't even allowed to spawn sub-processes or use Python threading.
App Engine does have a Java API. I just checked and found a Java MP3 decoder, and it is LGPL so you don't have to worry much about the license.
I don't know if there is any way to call Java code from Python code in App Engine, but you might try looking into that.
回答2:
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
回答3:
I just stumbled upon a real pure Python implementation:
- Hack a day: Decoding MP3 in Python
However, as the author noted, it is really slow (on his machine about 10 times slower than realtime).
回答4:
How about taking a look at this:
Python Audio Tools
来源:https://stackoverflow.com/questions/3049572/how-to-convert-mp3-to-wav-in-python