Esempio n. 1
0
 def testHFCOptimalThreshold(self):
     thresholds = map(lambda x: x / 20, range(0, 40, 5))
     best_evals = None
     best_f = 0
     best_threshold = 0
     for threshold in thresholds:
         evals = []
         for f in self.soundfiles:
             truthname = self.truth_dir + f.split(".")[0] + ".txt"
             srcname = self.sound_dir + f
             signal, fs = librosa.load(srcname)
             result = onset_detection.detect_onsets(signal,
                                                    fs,
                                                    rt="hfc",
                                                    units="time",
                                                    split_bands=True,
                                                    threshold=threshold)
             truth = mir_eval.io.load_events(truthname)
             evals.append(mir_eval.onset.evaluate(truth, result))
         f = averageOfMetric(evals, "F-measure")
         if f > best_f:
             best_f = f
             best_threshold = threshold
             best_evals = evals
     print("Optimal threshold", best_threshold)
     printEvaluation("HFC optimal threshold", self.metrics, best_evals)
Esempio n. 2
0
 def testPD(self):
     evals = []
     for f in self.soundfiles:
         truthname = self.truth_dir + f.split(".")[0] + ".txt"
         srcname = self.sound_dir + f
         signal, fs = librosa.load(srcname)
         result = onset_detection.detect_onsets(signal,
                                                fs,
                                                rt="pd",
                                                units="time")
         truth = mir_eval.io.load_events(truthname)
         evals.append(mir_eval.onset.evaluate(truth, result))
     printEvaluation("PD onset detection", self.metrics, evals)
Esempio n. 3
0
 def testHFCMultiband(self):
     evals = []
     for f in self.soundfiles:
         truthname = self.truth_dir + f.split(".")[0] + ".txt"
         srcname = self.sound_dir + f
         signal, fs = librosa.load(srcname)
         result = onset_detection.detect_onsets(signal,
                                                fs,
                                                rt="hfc",
                                                units="time",
                                                split_bands=True)
         truth = mir_eval.io.load_events(truthname)
         evals.append(mir_eval.onset.evaluate(truth, result))
     printEvaluation("HFC onset detection with multiple bands",
                     self.metrics, evals)
Esempio n. 4
0
def detect(sound):
    waveform = sound[:]
    waveform = np.abs(waveform)
    #show_waveform(waveform, "Squared wave", 311)

    # sw = smooth_wave(waveform)
    # show_waveform(sw, "Smoothed wave", 312)
    # plt.show()
    candidates = onset_detection.detect_onsets(waveform)
    print(candidates)

    # dis = np.zeros(waveform.shape)
    # dis -= 1
    # for i in candidates:
    #     dis[i] = 1
    # plt.plot(dis.tolist(), 'g')
    return candidates