Uses 911K of libraries. Click here for Pure Java version (11363L/60K).
!7 cmodule PerceptronVAD1 > DynImageSurface { switchable int w = 5; switchable int h = 10; switchable int nMaxExamples = 2000; switchable S teacherModule; // an accurate VAD that we learn from switchable bool learn; switchable bool train; switchable double c = 1; transient S status; new Perceptron perceptron; transient double[] parameters; transient ReliableSingleThread rstTrain = dm_rst(this, r train); transient double lastError; visualize { JComponent c = super.visualize(); imageSurface_pixelated(imageSurface); setZoom(20); ret centerAndSouth(c, withMargin(vstackWithSpacing( centerAndEastWithMargin(dm_textFieldWithLabel teacherModule(), dm_checkBox learn()), centerAndEastWithMargin(dm_label status(), dm_checkBox train())))); } start { updateStatus(); dm_requireLiveAudioFFT(); dm_audioInput_enableSendOutClonedData(); dm_vmBus_onMessage_q newAudioFrequencyImageFromData(voidfunc(virtual BWImage _img, short[] fromData) { BWImage img = cast quickImport(_img); BWIntegralImage ii = new(img); BWImage bw = scaleDownUsingIntegralImageBW(ii, w, h); setImage(bw); parameters = concatDoubleArrays( bwImage_averageBrightnessPerRow(bw), bwImage_standardDeviationPerRow(bw)); if (teacherModule != null && learn) { Bool va = cast dm_call(teacherModule, 'hasVoiceActivity, fromData); // TODO: wait a bit while va == null print("va: " + va); if (va != null && l(perceptron.examples) < nMaxExamples) { perceptron.addExample(parameters, va); change(); updateStatus(); rstTrain.trigger(); } } }); dm_watchFieldAndNow c(r {perceptron.c = c }); dm_watchFieldAndNow train(rstTrain); } void train enter { if (!train) ret; print("Training"); long n = 0; for ping (Double error : perceptron.trainingIterator()) { if (deleted || !train) ret; ++n; if (error != null) lastError = error; if (error != null || (perceptron.trainingRound % 10000) == 0) { //perceptron.printWithWeights(); updateStatus(); change(); } } print("Trained (" + nRounds(n) + ")"); } void updateStatus { setField(status := "Error: " + firstNonNegativeDouble_orMinus1(perceptron.error, lastError) + " for " + nExamples(perceptron.examples) + ", " + nRounds(perceptron.trainingRound)); } }
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: | 276 / 1514 |
Version history: | 29 change(s) |
Referenced in: | [show references] |