Uses 911K of libraries. Click here for Pure Java version (11363L/60K).
1 | !7 |
2 | |
3 | cmodule PerceptronVAD1 > DynImageSurface {
|
4 | switchable int w = 5; |
5 | switchable int h = 10; |
6 | switchable int nMaxExamples = 2000; |
7 | switchable S teacherModule; // an accurate VAD that we learn from |
8 | switchable bool learn; |
9 | switchable bool train; |
10 | switchable double c = 1; |
11 | transient S status; |
12 | new Perceptron perceptron; |
13 | transient double[] parameters; |
14 | transient ReliableSingleThread rstTrain = dm_rst(this, r train); |
15 | transient double lastError; |
16 | |
17 | visualize {
|
18 | JComponent c = super.visualize(); |
19 | imageSurface_pixelated(imageSurface); |
20 | setZoom(20); |
21 | ret centerAndSouth(c, withMargin(vstackWithSpacing( |
22 | centerAndEastWithMargin(dm_textFieldWithLabel teacherModule(), dm_checkBox learn()), |
23 | centerAndEastWithMargin(dm_label status(), dm_checkBox train())))); |
24 | } |
25 | |
26 | start {
|
27 | updateStatus(); |
28 | dm_requireLiveAudioFFT(); |
29 | dm_audioInput_enableSendOutClonedData(); |
30 | |
31 | dm_vmBus_onMessage_q newAudioFrequencyImageFromData(voidfunc(virtual BWImage _img, short[] fromData) {
|
32 | BWImage img = cast quickImport(_img); |
33 | BWIntegralImage ii = new(img); |
34 | BWImage bw = scaleDownUsingIntegralImageBW(ii, w, h); |
35 | setImage(bw); |
36 | parameters = concatDoubleArrays( |
37 | bwImage_averageBrightnessPerRow(bw), |
38 | bwImage_standardDeviationPerRow(bw)); |
39 | |
40 | if (teacherModule != null && learn) {
|
41 | Bool va = cast dm_call(teacherModule, 'hasVoiceActivity, fromData); |
42 | // TODO: wait a bit while va == null |
43 | print("va: " + va);
|
44 | if (va != null && l(perceptron.examples) < nMaxExamples) {
|
45 | perceptron.addExample(parameters, va); |
46 | change(); |
47 | updateStatus(); |
48 | rstTrain.trigger(); |
49 | } |
50 | } |
51 | }); |
52 | |
53 | dm_watchFieldAndNow c(r {perceptron.c = c });
|
54 | dm_watchFieldAndNow train(rstTrain); |
55 | } |
56 | |
57 | void train enter {
|
58 | if (!train) ret; |
59 | print("Training");
|
60 | long n = 0; |
61 | for ping (Double error : perceptron.trainingIterator()) {
|
62 | if (deleted || !train) ret; |
63 | ++n; |
64 | if (error != null) |
65 | lastError = error; |
66 | if (error != null || (perceptron.trainingRound % 10000) == 0) {
|
67 | //perceptron.printWithWeights(); |
68 | updateStatus(); |
69 | change(); |
70 | } |
71 | } |
72 | print("Trained (" + nRounds(n) + ")");
|
73 | } |
74 | |
75 | void updateStatus {
|
76 | setField(status := "Error: " + firstNonNegativeDouble_orMinus1(perceptron.error, lastError) + " for " + nExamples(perceptron.examples) + ", " + nRounds(perceptron.trainingRound)); |
77 | } |
78 | } |
Began life as a copy of #1026914
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1026924 |
| Snippet name: | Perceptron-Based VAD [dev.] |
| Eternal ID of this version: | #1026924/30 |
| Text MD5: | 1fdcbcd9aac4b8c5fe88386f875702e0 |
| Transpilation MD5: | b55838d5042ed1b9481846616177d145 |
| Author: | stefan |
| Category: | javax / audio analysis |
| Type: | JavaX source code (Dynamic Module) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-02-02 21:19:50 |
| Source code size: | 2575 bytes / 78 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 588 / 1874 |
| Version history: | 29 change(s) |
| Referenced in: | [show references] |