!7 cmodule ListenOnNoise > DynPrintLogAndEnabled { switchable double threshold = 50; switchable double interval = 10.0; 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); }); } }