Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting an amplitude list from *.wav file for use in Python

I'm having a little bit of programing and conversion trouble. I'm designing an AI to recognize notes played by instruments and need to extract the raw sound data from a wave file. My objective is to perform a FFT operation over chunks of time in the file for use by the AI. For this I need an amplitude list of the audio file, but I can't seem to find a conversion technique that will work. The files start as MP3's and then I convert them to wav file, but I always end up with a compressed file that spits out gibberish when I try to read it. Does anyone know how I might convert the wav file to something that would be compatible with Python's wave module or even something that would directly convert the data into an amplitude list?

like image 957
AlexL Avatar asked Feb 03 '11 19:02

AlexL


2 Answers

The default Python wave module isn't very thorough. You might try the one included in scipy as an alternative.

Check out: Reading *.wav files in Python

If you're going to do any numerical heavy lifting with the audio, scipy might be your best option anyway.

like image 141
bbrame Avatar answered Oct 11 '22 14:10

bbrame


I believe Python can read .dat files. You can use SoX to turn mp3s or wavs or whatever into .dat files that are simply a text list of "time - Left amp - Right amp"

The code is simply sox soundfile.mp3 soundfile.dat

http://sox.sourceforge.net/

Sox is command line - I run it with Terminal on my mac, but anything that understands Bash or Linux commands should work depending on what cpu you're using.

Hope that helps!

You might want to look at Pure Data too, it's got some nice FFT transforms built into an intuitive graphical programming language.

like image 23
Nash Rose Avatar answered Oct 11 '22 13:10

Nash Rose