Porcupine Wake Word
React Quick Start
Platforms
- Chrome & Chromium-based browsers
- Edge
- Firefox
- Safari
Requirements
- Picovoice Account and AccessKey
- Node.js 16+
- React 17.0+
- npm
Picovoice Account & AccessKey
Signup or login to Picovoice Console to get your AccessKey
.
Make sure to keep your AccessKey
secret.
Quick Start
Setup
Install Node.js.
Install the npm packages:
Usage
To initialize Porcupine Wake Word
, you'll need a Porcupine keyword file (.ppn
) as well as a model file (.pv
). Place these files in the project's public directory or generate base64 representations of the files using the built-in script:
Create a porcupineKeyword
and a porcupineModel
object with either of the methods above:
Import and call the usePorcupine
Hook, and initialize Porcupine Wake Word
with your AccessKey
, porcupineKeyword
, and porcupineModel
:
To detect for multiple keywords, call init
with an array of keywords:
The Hook will take care of microphone access and audio downsampling (
via @picovoice/web-voice-processor
).
To start audio recording and processing:
To stop audio recording and processing:
Allocated resources are automatically freed on unmount, but can also be done explicitly:
Custom Keywords
Create custom keywords using the Picovoice Console.
Train and download a Porcupine Wake Word keyword model (.ppn
) for the target platform Web (WASM)
.
This model file can be used directly with publicPath
, but, if base64
is preferable, convert the .ppn
file to a base64
JavaScript variable using the built-in pvbase64
script:
Similar to the model file (.pv
), keyword files (.ppn
) are saved in IndexedDB to be used by Web Assembly.
Either base64
or publicPath
must be set for each keyword to instantiate Porcupine Wake Word.
If both are set, Porcupine Wake Word will use the base64
model.
An arbitrary label
is required to identify the keyword once the detection occurs.
Non-English Languages
In order to use Porcupine Wake Word with other languages, you need to use the corresponding model file (.pv
) for the desired language. The model files for all
supported languages are available on the Porcupine GitHub repository.
Demo
For the Porcupine Wake Word React SDK, there is a React demo project available on the Porcupine GitHub repository.
Setup
Clone the Porcupine Wake Word repository from GitHub:
Usage
- Install dependencies:
- Run the demo with the
start
script with a language code to start a local web server hosting the demo in the language of your choice (e.g.de
-> German,ko
-> Korean). To see a list of available languages, run start without a language code.
Open http://localhost:3000 to view it in the browser.
Enter your access key and press on
Init Porcupine
to start recording for keyword detections.
Resources
Packages
- @picovoice/porcupine-react on the npm registry
- @picovoice/porcupine-web on the npm registry
- @picovoice/web-voice-processor on the npm registry