Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

58
LINES

< > BotCompany Repo | #1018810 // Distinguish Yes and No Spike [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 11806K of libraries. Click here for Pure Java version (11900L/86K).

1  
!7
2  
3  
sclass Analyzer {
4  
  static int baseSize = 1024;
5  
  
6  
  S word1, word2;
7  
  Rect rect; // in baseSize*baseSize
8  
  float threshold;
9  
  
10  
  S analyze(BWImage img) {
11  
    Rect r = rescaleRect(rect, baseSize, baseSize, img.getWidth(), img.getHeight());
12  
    double b = clipBWImage(img, r).averageBrightness();
13  
    //print(r + " => " + b);
14  
    ret b >= threshold ? word1 : word2;
15  
  }
16  
}
17  
18  
static LPair<S, BWImage> images = new L;
19  
sS word1 = "yes", word2 = "no";
20  
21  
p-exp {
22  
  L<File> files = audioRecordingsWithSingleClip();
23  
  for (File f : allRecordings()) {
24  
    S word = wordFromAudioFileName(f);
25  
    if (!eqicOneOf(word, word1, word2)) continue;
26  
    images.add(pair(word, bwAutoContrast(audio_clipFromLastEntryPoint(audioFileToFrequencyImage(f)))));
27  
    print(fileName(f));
28  
  }
29  
  
30  
  showImage(second(random(images)));
31  
  findBestAnalyzer();
32  
}
33  
34  
svoid findBestAnalyzer {
35  
  final new Best<Analyzer> best;
36  
  final new AIStrategy_RandomWithVariation<Analyzer> strategy;
37  
  strategy.random = func -> Analyzer { randomAnalyzer() };
38  
  strategy.submit = func(final Analyzer a) -> double {
39  
    new Scorer scorer;
40  
    
41  
    for (Pair<S, BWImage> img : images)
42  
      scorer.add(eqic(img.a, a.analyze(img.b)));
43  
      
44  
    if (best.put(a, scorer!))
45  
      print(scorer + " / " + struct(a)); 
46  
    ret scorer!;
47  
  };
48  
  thread { while licensed { strategy.go(); } }
49  
}
50  
51  
static Analyzer randomAnalyzer() {
52  
  bool flip = tossCoin();
53  
  ret nu(Analyzer,
54  
    word1 := flip ? word1 : word2,
55  
    word2 := flip ? word2 : word1,
56  
    rect := randomRect(Analyzer.baseSize, Analyzer.baseSize),
57  
    threshold := randomFloat());
58  
}

Author comment

Began life as a copy of #1018800

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018810
Snippet name: Distinguish Yes and No Spike [OK]
Eternal ID of this version: #1018810/12
Text MD5: 211a46907a1902addef4b1ae3b838db1
Transpilation MD5: f8c2f4982e90d4ca5104a8f4166d0077
Author: stefan
Category: javax / audio
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-13 22:03:39
Source code size: 1636 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 294 / 732
Version history: 11 change(s)
Referenced in: [show references]