Picovoice SDK
React Web 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 obtain your AccessKey
.
Make sure to keep your AccessKey
secret.
Quick Start
Setup
Install Node.js.
Install the npm packages:
Usage
To initialize Picovoice
, you'll need a Porcupine keyword file (.ppn
)
and model file (.pv
), as well as a
Rhino context file (.rhn
)
and model file (.pv
). Place these files in the project's public directory or generate base64 representations of the files using the built-in script:
Pass the path to the file or use the base64 string:
Import and call the usePicovoice
Hook, and initialize Picovoice
with your AccessKey
, porcupineKeyword
, porcupineModel
, rhinoContext
, and rhinoModel
:
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 & Contexts
Create custom keywords and contexts using the Picovoice Console.
Train a Porcupine keyword to obtain a keyword file (.ppn
) and a Rhino context to obtain a context file (.rhn
).
To use them with the Web SDK, train the keywords and contexts for the target platform Web (WASM)
.
These model files can be used directly with publicPath
, but, if base64
is preferable, convert to base64
JavaScript variable using the built-in pvbase64
script:
Similar to the model file (.pv
), these files are saved in IndexedDB to be used by Web Assembly.
Either base64
or publicPath
must be set for each file to initialize Picovoice. If both are set, Picovoice will use
the base64
model.
Non-English Languages
In order to use Picovoice with different languages you need to use the corresponding model file (.pv
) for the desired
language. The model files for all
supported languages are available in the Porcupine
and Rhino GitHub repositories.
Demo
For the Picovoice React SDK, there is a React demo project available on the Picovoice GitHub repository.
Setup
Clone the Picovoice 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 Picovoice
to start the demo.