Search code examples
pythonaudiofrequencypyaudio

How to get frequency of sound using Zero crossing


I am currently trying to get the frequency of the audio data that I have obtained from pyAudioStream.read(). I have already gotten the number of zero crosses there were in the chunk but now I want to determine the frequency based on the zero crosses, I heard it was possible but idk how to do it and I cant seem to find it on a google search, can anyone help me out here?


Solution

  • Let assume that the variable num_crossings holds the number of zero crossings in your chunk.

    Therefore, you have:

    frequency = (num_crossings * sampling_rate / (2 * (len(chunk))))
    

    For frequency detection, you can also use Fourier transform (with numpy.fft for instance).