scope trainVAD. sclass TrainVAD { replace Recognizer with F1. new Best best; LPair trainingList; int clipLength; Recognizer go() { final BWImage img1 = frequencyImage(voiceMegaMix()); final BWImage img2 = frequencyImage(nonVoiceMegaMix()); clipLength = iround(2.0*spectro_pixelsPerSecond()); int stepSize = clipLength/4; print(+clipLength); L images1 = map(func(IntRange r) -> BWImage { bwHorizontalClip(img1, r) }, stepIntRange(clipLength, intRange(0, img1.getWidth()), stepSize)); L images2 = map(func(IntRange r) -> BWImage { bwHorizontalClip(img2, r) }, stepIntRange(clipLength, intRange(0, img2.getWidth()), stepSize)); print(allImageSizes(concatLists(images1, images2))); print(l(images1) + " + " + l(images2) + " images"); trainingList = trueFalseBPairs(images1, images2); // dummy recognizers first test(func(BWImage img) -> bool { false }); test(func(BWImage img) -> bool { true }); // now actual ones for (int streakLength = 1; streakLength <= clipLength/2; streakLength++) test(nu(Rec1, +streakLength)); ret best!; } void test(Recognizer r) { scorePreciseRecognizer(best, r, trainingList); } void showErrors(Recognizer r) { if (r == null) ret; new L errorImages; for (Pair p : trainingList) if (recognizer.get(p.a) != p.b) errorImages.add(p.a); if (nempty(errorImages)) showImage("Errors", mergeBWImagesVertically(errorImages)); } } sclass #Rec1 extends F1 { int streakLength; public Bool get(BWImage img) { ret hasIntRangesLongerThan(streakLength, audio_streaksUsingBand_v1(img, audio_bestBandForEntryPoints())); } toString { ret struct(this); } } static F1 trainVAD() { new TrainVAD() t; F1 best = t.go(); t.printErrors(best); ret best; } end scope