3

I have simple case, i'm recording bee sound in Bee have by python pyAudio. After recording i have to split this record in 10 sec chunks and analyze this chunks by python wave, numpy or python scipy, numpy, i don't know what is easiest way. I would like to read the record then split it to 10 sec chunk and apply fft or rfft and after that i need get dominant frequencies in Hz in chunk. I collect this values with timestamp in histogram for histogram plot.

Right now i have some examples where i can get whole record and make plot by python matplotlib, scipy.signal but i don't know how to separated it into listo of Hz values.

If i have completely wrong way please tell me. Thx for advice.

import numpy as np
import struct, wave

def main():
   audio = wave.open('wav_data/18-08-07_09_10_12.wav', 'rb')
   rate = audio.getframerate()
   num_frames = audio.getnframes()
   dur = int(num_frames / rate)
   fmt = "%ih" % rate

   for x in range(dur):
     data = audio.readframes(rate)
     data_int = struct.unpack(fmt, data)
     data_np = np.array(data_int, dtype='b')
     w = np.fft.rfft(data_np)
     freqs = np.fft.fftfreq(len(w))
     idx = np.argmax(w)
     freq = freqs[idx]
     freq_in_hz = abs(freq * rate)
     print(freq_in_hz)

if __name__ == "__main__":
   main()

0 Answers0