擅长:python、mysql、java
<p>我发现一些代码使用问题<a href="https://stackoverflow.com/questions/53308674/audio-frequencies-in-python">Audio Frequencies in Python</a>实现了这一点,我将把它放在下面:</p>
<pre class="lang-py prettyprint-override"><code> # compute FFT
fftData=abs(np.fft.rfft(data_int))**2
# find the maximum
which = fftData[1:].argmax() + 1
# use quadratic interpolation around the max
if which != len(fftData)-1:
y0,y1,y2 = np.log(fftData[which-1:which+2:])
x1 = (y2 - y0) * .5 / (2 * y1 - y2 - y0)
# find the frequency and output it
thefreq = (which+x1)*self.RATE/self.CHUNK
print(f"The freq is {thefreq} Hz.")
else:
thefreq = which*self.RATE/self.CHUNK
print (f"The freq is {thefreq} Hz.")
</code></pre>