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)
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)
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)
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