User's whistle detector/analyzer written in pure javascript.
Whistle.js acquires the user's microphone input via getUserMedia and keeps monitoring certain frequencies, believed to be the "whistling" ones. When their level becomes high enough, an event ("whistle" by default) is triggered on an element ("document" by default).
-
Download
whistle.js
and include it somewhere in your html<script src="whistle.js"></script>
-
Initialize it whenever you want or when the document is ready
whistle.init()
-
The
init()
method takes three optional parameters:
whistleEventName [string]
- by setting this you can specify the name of the event triggered on user's whistleonce [boolean]
- if set to true, the whistle event will be triggered only at the first time user whistlesprecision [string]
- if set to 'low', the whistle analyser will be more tolerant. Useful if you need to capture the intensity of whistles
-
Set an event handler for the whistle
document.addEventListener("whistle", function() { alert("whistle detected!"); }, false)
-
Optionally check if user is whistling in real time and/or how intense his whistles are
setInterval(function() { if(whistle.whistling) { console.log("user's whistling at the moment"); console.log("intensity: " + whistle.intensity); } }), 10)
-
You can also check if whistle.js is ready and the microphone prompt has been accepted by user
document.addEventListener("whistleReady", function() { alert("whistle.js is up and running") }, false)
And that's it! Surprised?
Feel free to send any improvements or report issues.
Copyright 2013 Michal Siwek
Released under the terms of GNU General Public License (version 3 or later)