How do I find the peak frequency of a wav file in python?
import sounddevice as sd
import scipy
import numpy as np
from scipy.io import wavfile as wav
from scipy.io.wavfile import write ,read
from scipy import fftpack as scfft
from matplotlib import pyplot as plt

fs = 44100  
seconds = 3
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=1)
sd.wait()  
write('output.wav', fs, myrecording)   

fs_rate, signal = read("output.wav")
l_audio = len(signal.shape)
N = signal.shape[0]
secs = N / float(fs_rate)
Ts = 1.0/fs_rate 
t = scipy.arange(0, secs, Ts) 
FFT = abs(scipy.fft(signal))
FFT_side = FFT[range(N//2)] 
freqs = scipy.fftpack.fftfreq(signal.size, t[1]-t[0])
fft_freqs = np.array(freqs)
freqs_side = freqs[range(N//2)] 
fft_freqs_side = np.array(freqs_side)

volume=np.array(abs(FFT_side))
audible=np.where(volume&gt;5)

HighestAudibleFrequency=max(freqs_side[audible])
print(HighestAudibleFrequency)


The above code records audio for 3 seconds from the microphone and outputs the highest frequency detected in the 3 seconds. Sorry for the code format, i dont know how to make it look better