!7 cmodule2 ListenOnNoise > DynPrintLogAndEnabled { switchable int threshold = 50; switchable int interval = 10; transient float lastVolume; transient Q q; 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; }); }); dm_onUserUtterance("stop listening", r { setEnabled(false); }); } afterVisualize { addButton(dm_intSpinnerWithLabel interval(1, 600)); addButton(dm_intSpinnerWithLabel threshold(1, 80)); } }