i want to print separate frequency present in a music file. if freq amp is grater than threshold. then it will brinted.
import pyaudio
import wave
import numpy as np
chunk = 2048
wf = wave.open('/home/pi/music.wav', 'rb')
swidth = wf.getsampwidth()
RATE = wf.getframerate()
window = np.blackman(chunk)
p = pyaudio.PyAudio()
stream = p.open(format =
p.get_format_from_width(wf.getsampwidth()),
channels = wf.getnchannels(),
rate = RATE,
output = True)
data = wf.readframes(chunk)
while len(data) != '':
stream.write(data)
indata = np.array(wave.struct.unpack("%dh"%(len(data)/swidth),\
data))
fftdata=abs(np.fft.rfft(indata))**2
freq1=np.fft.fftfreq(len(indata))
for i in range(len(freq1)):
freq = freq1[i]
print freq
data = wf.readframes(chunk)
it is printing frequencies 0.something. not getting actual frequiencies
Your loop over
freq1
is wrong. To usei
as the index forfreq1
, try this:Or alternatively,