def getFreq(audio, rate):
  #Filter with Hanning Window
  window = hann(len(audio))
  audio = audio * window
  #run rfft
  spectrum = rfft(audio)
  #find peak of signal
  #This segment is Copyright (c) 2007, Imri Goldberg
  signature = [peak for peak in fft_utils.find_peaks(spectrum,2, 1e6) if peak[0]>10]
  print signature, " signature\n"
  if len(signature) == 0:
    #0 indicates REST. Returning none is faulty.
   return 0
  note = min([x[0] for x in signature])
  return float(note)*2*rate/(2**13)
Esempio n. 2
0
def getFreq(audio, rate):
    #Filter with Hanning Window
    window = hann(len(audio))
    audio = audio * window
    #run rfft
    spectrum = rfft(audio)
    #find peak of signal
    #This segment is Copyright (c) 2007, Imri Goldberg
    signature = [
        peak for peak in fft_utils.find_peaks(spectrum, 2, 1e6) if peak[0] > 10
    ]
    print signature, " signature\n"
    if len(signature) == 0:
        #0 indicates REST. Returning none is faulty.
        return 0
    note = min([x[0] for x in signature])
    return float(note) * 2 * rate / (2**13)
    def recognize_note(self, audio_data):
        """return the note played in the given audio data
        Params:
            audio_data - a buffer of samples
        Return value:
            The frequency of the playing note.
            If no playing note is found, None is returned.
        """
        mult = fft_utils.awindow(len(audio_data))
        final_fft = numpy.array(map(abs, numpy.fft.fft(audio_data*mult)[:self.fft_size/12]))

        signature = [peak for peak in fft_utils.find_peaks(final_fft,2) if peak[0]>10]

        if len(signature) == 0:
            return

        note = min([x[0] for x in signature])
        return self.compute_freq(note)
Esempio n. 4
0
    def recognize_note(self, audio_data):
        """return the note played in the given audio data
        Params:
            audio_data - a buffer of samples
        Return value:
            The frequency of the playing note.
            If no playing note is found, None is returned.
        """
        mult = fft_utils.awindow(len(audio_data))
        final_fft = numpy.array(
            map(abs,
                numpy.fft.fft(audio_data * mult)[:self.fft_size / 12]))

        signature = [
            peak for peak in fft_utils.find_peaks(final_fft, 2) if peak[0] > 10
        ]

        if len(signature) == 0:
            return

        note = min([x[0] for x in signature])
        return self.compute_freq(note)