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

梦想与她 提交于 2019-12-10 14:23:45

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4890619/extracting-an-amplitude-list-from-wav-file-for-use-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!