rivques
rivques

Reputation: 103

Get frequency of a PyAudio block

I'm writing a program that involves PyAudio. I already capture a block using stream.read() and get its amplitude using an RMS function from elsewhere on StackOverflow. However, I'd like to also be able to get the (average?) frequency of that block. I think I'll need to use a (fast?) Fourier transform, since my understanding is that it can "interpolate periodic functions," which sounds like exactly what I need. The issue is that I have no idea how I would go around implementing this. Ideally, I'd have a function that takes in a block and spits out a frequency in Hz.

EDIT: Thanks to @MSalters, I now know that this question is not quite possible. Correction: Ideally, I'd have a function that would take a block and spit out an array of frequencies (or other descriptive values).

Upvotes: 0

Views: 329

Answers (1)

MSalters
MSalters

Reputation: 179819

The frequency probably does not exist - the audio fragment may contain a chord with multiple notes, or percussion instruments. But as you suspected, the FFT is the correct tool. It will tell you the amplitude for each individual frequency.

Upvotes: 1

Related Questions