!7 import static x30_pkg.x30_util.VF1; sclass ListenOnNoise > DynPrintLog { float threshold = 50f; double interval = 10.0; volatile bool enabled = true; transient float lastVolume; transient Q q; visualize { ret centerAndSouthWithMargins(super.visualize(), jrightalignedline(dm_fieldCheckBox('enabled))); } void start { q = dm_startQ(); dm_addAudioListener(voidfunc(short[] data) { if (!enabled) ret; // Quickly calculate the volume final float vol = shortSamplesToPercentVolume(data); // Do everything else in our own thread; don't pile up if (q.isEmpty()) q.add(r { //print("vol: " + vol); if (vol >= threshold && lastVolume < threshold) { printWithTime("Got noise (" + iround(vol) + "%)"); /*O katze = dm_getModule(dm_requireModule("#1016461/Katze")); call(katze, 'listenJustOnce);*/ dm_enableSpeechRecognitionFor(interval, "Noise"); } lastVolume = vol; }); }); } }