I am attempting to write a program that detects the frequency of a sound in a .wav file. I would like to do this with exclusively native python, no third-party modules. I used the built-in read() and open() functions and got some strange results:
with open('pcm-test.wav', 'rb') as f:
data = f.read(255)
print data
When I run it, I get this:
>>>
RIFF$ÈWAVEfmt data
>>>
What am I doing wrong? Any advice would be appreciated. Thanks!
EDIT
I suppose I phrased this wrong. I'm looking for the frequency of the tone in the .wav file, not the sample rate. I have an algorithm for computing frequency based on an array of amplitudes, but I have no way of finding it. I guess my question would be how can I get raw amplitude data from the .wav file and store it as a list, tuple, etc.
What am I doing wrong?
Nothing, everything works just fine. Next, parse the WAVE header ( http://soundfile.sapp.org/doc/WaveFormat/ ) and get your sample rate.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.