Skip to content

frymanofer/ReactNative_WakeWordDetection

Repository files navigation

ReactNative KeywordsDetection by Davoice

GitHub release License

By DaVoice.io

Twitter URL

Welcome to Davoice WakeWord / Keywords Detection – Wake words and keyword detection solution designed by DaVoice.io.

Latest news

  • New Car Parking Example: Checkout our new Voice Activated Car Parking example, with voice control both in Foreground and Background: example_car_parking/.

Features

  • High Accuracy: Our advanced machine learning models deliver top-notch accuracy.
  • Easy to deploy with React Native: Check out our example: "rn_example/DetectingKeyWords.js". With a few simple lines of code, you have your own keyword detecting enabled app.
  • Cross-Platform Support: Integrate Davoice KeywordsDetection into React-Native Framework. Both iOS and Android are supported.
  • Low Latency: Experience near-instantaneous keyword detection.

Platforms and Supported Languages

  • React-Native Android: React Native Wrapper for Android.
  • React-Native iOS: React Native Wrapper for iOS.

Contact

For any questions, requirements, or more support for React-Native, please contact us at info@davoice.io.

Installation and Usage

npm install - package

(Soon to be released. You will be able to use: npm install react-native-davoice-keywordsdetection)

Demo Instructions

To run the demo:

  1. Clone the repository:

    git clone https://[YourGittName]:[Token].com/frymanofer/ReactNative_WakeWordDetection.git
    
  2. Navigate to the example directory:

    cd example
    
  3. For Android:

    npm run android
    

    Depending on your system, you may be required to press "a" for Android.

    Note: If you don't have an Android environment setup (Gradle, Android device or Emulator, Java, etc.) and need help, please contact us at ofer@davoice.io.

  4. For iOS:

    npm run ios
    

    Depending on your system, you may be required to press "i" for iOS.

    Note: If you don't have an iOS environment setup (Xcode, CocoaPods, iOS device or Emulator, etc.) and need help, please contact us at ofer@davoice.io.

Screenshots from the demo App

  1. Make sure you allow Audio Permission The app need to ask Audio permission, make sure you allow it as it is necessary for wake word detection.

    Audio Permission Prompt

  2. If You are using Android Emulator - make sure you enable Microphone as below: The settings screen showing virtual microphone configuration in the Android emulator.

    Microphone Settings

  3. Listening for Wake Word: The app is actively listening for the wake word "Need Help Now."

    Listening for Wake Word

  4. Wake Word Detected: The app has detected the wake word "Need Help Now."

    Wake Word Detected

Usage Example

Below is a simple JavaScript code showing how to use Davoice KeywordsDetection:

// Import the main class
import KeyWordRNBridge from 'react-native-davoice-keywordsdetection';

// Setup your callback on keyword / wakeword detected
const onKeyWordDetected = async (keywordIndex) => {
  // Do whatever you need on callback
  // Stop searching for Keywords if it makes sense - KeyWordRNBridge.stopKeyWord();
};

// Setup and activate keywords detection
try {
  let modelParams = {
    modelName: "my_key_word.onnx", // replace with your model
    threshold: 0.9999, // false positive sensitivity
    falsePositiveChecks: 2 // How many checks for false positives
  };

  // Initialize the detection
  const result = await KeyWordRNBridge.initKeywordDetection(
    modelParams.modelName, 
    modelParams.threshold, 
    modelParams.falsePositiveChecks
  );

  await KeyWordRNBridge.setKeywordDetectionLicense(
          "MTcyODkzOTYwMDAwMA==-XPLwWg6m4aFC9YMJZu0d0rKIh2AsExYixyeCpiVQmpE="); // Set a valid license!!!!

  // Setup the callback
  KeyWordRNBridge.onKeywordDetectionEvent((event) => {
    onKeyWordDetected(event);
  });

  // Now we are set - you can start listening and detect key words
  KeyWordRNBridge.startKeywordDetection();
} catch (e) {
  console.log("ERROR loadDavoice", e);
}

Benchmark.

Our customers have benchmarked our technology against leading solutions, including Picovoice Porcupine, Snowboy, Pocketsphinx, Sensory, and others. In several tests, our performance was comparable to Picovoice Porcupine, occasionally surpassing it, however both technologies consistently outperformed all others in specific benchmarks. For detailed references or specific benchmark results, please contact us at ofer@davoice.io.

Activating Microphone while the app operates in the background or during shutdown/closure.

This example in the Git repository enables Android functionality in both the foreground and background, and iOS functionality in the foreground. However, we have developed an advanced SDK that allows the microphone to be activated from a complete shutdown state on Android and from the background state on iOS. If you require this capability for your app, please reach out to us at ofer@davoice.io.

Example for iOS Background State

Apple restricts background microphone access for privacy and battery efficiency. However, certain applications, such as security apps, car controlling apps, apps for the blind or visually impaired may require this functionality.

Below is an example for one of the workarounds we have done in order to activate microphone with an empty listener. This approach avoids unnecessary battery usage until real audio capture is needed, at which point you can swap the placeholder listener with the actual microphone callback.

The example below, built in React Native, demonstrates this approach. The function backgroundMicEmptyListener() creates a minimal listener with negligible CPU impact, only processing the function call and return.

const handleAppStateChange = (nextAppState) => {
  console.log("handleAppStateChange(): ", nextAppState);
  
  if (nextAppState === 'background') {
    console.log("nextAppState === 'background'");
    BackgroundJob.start(backgroundMicEmptyListener, backgroundOptions)
      .then(() => {
        console.log('Background job started successfully');
      })
      .catch((err) => {
        console.error('Error starting background job:', err);
      });
  }
}

Links

Here are wakeword detection GitHub links per platform: