blowawish v1.0.10
Blow A Wish
❯ Installation
npm i blowawish
❯ Extra Attention
Accessing the microphone is only available from secure contexts.\ The website needs an SSL certificate.
❯ Usage
const Wish = require('blowawish');
const wish = new Wish(function() {
// Error callback :: Browser not supported
});
if (wish.supported()) {
wish.startListening(
function() {
// Success callback :: Microphone enabled
// Countdown 3 - 2 - 1 :: Start Analyzing
wish.startAnalyzing(0.8, function() {
// Success callback :: Blow detected
// Stop the script
wish.stopListening();
}
},
function(error) {
// Error calback :: Microphone not found or not enabled
}
);
}
❯ Methods
supported()
Returns: Boolean
Whether the browser is supported. If not, provide a fallback scenario.
startListening(successCallback, errorCallback)
successCallback: Function
errorCallback: Function(error)
Turn the microphone on.\ At this point, the browser will ask for permission to access the microphone.
- successCallback: The microphone has been turned on successfully.
- errorCallback: The microphone is not found or not enabled. Provide a fallback scenario.
startAnalyzing(strength, successCallback)
strength: Number
between 0 and 1 (for example: 0.8 => 80% strength)\
successCallback: Function
Start analyzing the microphone input for a "blow" detection. The success callback function is invoked as soon as the detection has been successfull.
startListening() must have succeeded before using startAnalyzing().
stopListening()
Turn the microphone off and stop analyzing.
stopAnalyzing()
Stop analyzing.\ This does not turn off the microphone.
getSoundLevel()
Returns: Number
Read the volume level of the microphone.
startListening() must have succeeded before using startAnalyzing().
Returns:
- 0: Lowest value
- 1: Highest value
Usage in: window.requestAnimationFrame()
function frame() {
console.log(wish.getSoundLevel() * 100 + "%"));
window.requestAnimationFrame(frame);
}
window.requestAnimationFrame(frame);
❯ Dependencies
None