识别音频的音调 [英] Recognising tone of the audio

查看:47
本文介绍了识别音频的音调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一把吉他,我需要我的电脑能够分辨正在演奏的音符,识别音色.可以用python来做,用pygame也可以吗?能够在 pygame 中做到这一点会非常有帮助.

I have a guitar and I need my pc to be able to tell what note is being played, recognizing the tone. Is it possible to do it in python, also is it possible with pygame? Being able of doing it in pygame would be very helpful.

推荐答案

要识别音频信号的频率,您可以使用 FFT (快速傅立叶变换) 算法.据我所知,PyGame 没有办法录制音频,也不支持 FFT 变换.

To recognize the frequency of an audio signal, you would use the FFT (fast Fourier transform) algorithm. As far as I can tell, PyGame has no means to record audio, nor does it support the FFT transform.

首先,您需要从声卡中捕获原始采样数据;这种数据称为 PCM(脉冲编码调制).在 Python 中捕获音频的最简单方法是使用 PyAudio 库(Python 绑定到 PortAudio).GStreamer 也可以做到,这对您的目的来说可能有点过头了.以 48000 Hz 的速率捕获 16 位样本是非常典型的,而且可能是普通声卡所能提供的最好的结果.

First, you need to capture the raw sampled data from the sound card; this kind of data is called PCM (Pulse Code Modulation). The simplest way to capture audio in Python is using the PyAudio library (Python bindings to PortAudio). GStreamer can also do it, it's probably an overkill for your purposes. Capturing 16-bit samples at a rate of 48000 Hz is pretty typical and probably the best a normal sound card will give you.

拥有原始 PCM 音频数据后,您可以使用 scipy 库中的 fftpack 模块 通过 FFT 变换运行样本.这将为您提供所分析音频信号的频率分布,即特定频段中的信号强度.然后,就是找到信号最强的频率.

Once you have raw PCM audio data, you can use the fftpack module from the scipy library to run the samples through the FFT transform. This will give you a frequency distribution of the analysed audio signal, i.e., how strong is the signal in certain frequency bands. Then, it's a matter of finding the frequency that has the strongest signal.

可能需要一些额外的过滤来避免谐波频率我我不确定.

You might need some additional filtering to avoid harmonic frequencies I am not sure.

这篇关于识别音频的音调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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