1.0.10 • Published 5 years ago

blowawish v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago