简体   繁体   English

仅使用本机python从.wav文件读取数据

[英]Reading data from a .wav file using only native python

I am attempting to write a program that detects the frequency of a sound in a .wav file. 我试图编写一个程序来检测.wav文件中声音的频率。 I would like to do this with exclusively native python, no third-party modules. 我想只使用本机python,没有第三方模块来执行此操作。 I used the built-in read() and open() functions and got some strange results: 我使用了内置的read()和open()函数,并得到了一些奇怪的结果:

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. 我正在寻找.wav文件中音调的频率,而不是采样率。 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. 我想我的问题是如何从.wav文件中获取原始幅度数据并将其存储为列表,元组等。

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. 接下来,解析WAVE标头( http://soundfile.sapp.org/doc/WaveFormat/ )并获取采样率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM