Exemple #1
0
 def predict_sample(self, frames):
     freq, sp = clip_to_freq(frames)
     smooth_sp = smooth_freq(freq, sp, cutoff=600)
     lm_x, lm_y = local_maxima(freq, smooth_sp)
     sorted_maxima = [x for (y, x) in sorted(zip(lm_x, lm_y))]
     if len(sorted_maxima) < 100:
         sorted_maxima += [0 for i in range(100)]
     top_100 = sorted_maxima[:100]
     top_x = np.array(top_100[:self.sample_size]).flatten()
     return self.classifier.predict(top_x)
Exemple #2
0
def build_classifier(dir_name, sample_size=5, c="gnb"):
    files = os.listdir(dir_name)
    wav_files = [x for x in files if x.endswith(".wav")]
    classifier = AudioClassifier(sample_size, c)
    for fn in wav_files:
        file_full = os.path.join(dir_name, fn)
        frames = sample_audio(file_full, start=0)
        freq, sp = clip_to_freq(frames)
        smooth_sp = smooth_freq(freq, sp, cutoff=600)
        lm_x, lm_y = local_maxima(freq, smooth_sp)
        sorted_maxima = [x for (y, x) in sorted(zip(lm_x, lm_y))]
        if len(sorted_maxima) < 100:
            sorted_maxima += [0 for i in range(100)]
        top_100 = sorted_maxima[:100]
        top_x = np.array(top_100[:classifier.sample_size]).flatten()
        class_name = fn.split("_")[0]
        refit = False
        if len(set(classifier.classifier_y)) > 1:
            refit = True
        classifier.add_point(top_x, class_name, refit)
    return classifier