如何从输入音频流中提取频率信息(使用PortAudio)? [英] How to extract frequency information from an input audio stream (using PortAudio)?

查看:150
本文介绍了如何从输入音频流中提取频率信息(使用PortAudio)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PortAudio(PyAudio)录制声音(语音)并在屏幕上输出相应的声波.就像我一样,我无可救药,无法从音频流中提取频率信息,因此无法以Hz/时间形式绘制它.

I want to record sound (voice) using PortAudio (PyAudio) and output the corresponding sound wave on the screen. Hopeless as I am, I am unable to extract the frequency information from the audio stream so that I can draw it in Hz/time form.

这是一个示例代码段,可在五秒钟内录制并播放录制的音频,以防万一:

Here's an example code snippet that records and plays recorded audio for five seconds, in case it helps any:

p = pyaudio.PyAudio()

chunk = 1024
seconds = 5

stream = p.open(format=pyaudio.paInt16,
                channels=1,
                rate=44100,
                input=True,
                output=True)

for i in range(0, 44100 / chunk * seconds):
    data = stream.read(chunk)
    stream.write(data, chunk)

我希望从上述变量数据"中提取所需的信息. (或者将其他高级方法用于PortAudio或其他具有Python绑定的库.)

I wish to extract the needed information from the above variable "data". (Or use some other high-level approach with PortAudio or another library with Python bindings.)

非常感谢您的帮助!甚至音频分析智慧的模糊相关小知识也受到赞赏. :)

I'd be very grateful for any help! Even vaguely related tidbits of audio-analyzing wisdom are appreciated. :)

推荐答案

您想要的可能是音频数据的傅立叶变换.有几个软件包可以为您计算出来. scipynumpy是其中两个.它通常被称为快速傅立叶变换"(FFT),但这仅是算法的名称.

What you want is probably the Fourier transform of the audio data. There is several packages that can calculate that for you. scipy and numpy is two of them. It is often named "Fast Fourier Transform" (FFT), but that is just the name of the algorithm.

以下是其用法示例: https ://svn.enthought.com/enthought/browser/Chaco/trunk/examples/advanced/spectrum.py

这篇关于如何从输入音频流中提取频率信息(使用PortAudio)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆