wasmPicovoice - Web Quick Start

Platforms

  • Chrome & Chromium-based browsers
  • Edge
  • Firefox
  • Safari

Requirements

Picovoice Account & AccessKey

Signup or Login to Picovoice Console to get your AccessKey. Make sure to keep your AccessKey secret.

Quick Start

Setup

  1. Install Node.js.

  2. Install the Web Voice Processor and Picovoice Web Worker packages:

npm install @picovoice/picovoice-web-en-worker @picovoice/web-voice-processor

Usage

Create PicovoiceWorker using a Porcupine keyword file (.ppn), and a Rhino context file (.rhn):

import { PicovoiceWorkerFactory } from "@picovoice/picovoice-web-en-worker";
const keywordFileBase64 = // base64 of Porcupine keyword file (.ppn)
const contextFileBase64 = // base64 of Rhino context file (.rhn)
const picovoiceWorker = await PicovoiceWorkerFactory.create({
accessKey: "${ACCESS_KEY}",
porcupineKeyword: {custom: "${CUSTOM_KEYWORD_LABEL}", base64:keywordFileBase64},
rhinoContext: {base64: contextFileBase64}
});
picovoiceWorker.onmessage = (msg) => {
switch (msg.data.command) {
case 'ppn-keyword':
// wake word detected
break;
case 'rhn-inference':
const inference = msg.data.inference;
if (inference.isUnderstood) {
const intent = inference.intent;
const slots = inference.slots;
// take action based on inferred intent and slot values
} else {
// handle unsupported commands
}
break;
default:
break;
}
};

Initialize and start the Web Voice Processor to pass audio to the Picovoice Platform:

import { WebVoiceProcessor } from "@picovoice/web-voice-processor"
const webVoiceProcessor = await WebVoiceProcessor.init({
engines: [picovoiceWorker]
});
webVoiceProcessor.start();

Release resources explicitly when done with Picovoice:

webVoiceProcessor.release()
picovoiceWorker.sendMessage({command: "release"})

Custom Keywords & Contexts

Create custom keywords and contexts using the Picovoice Console. Train the models for the target platform WebAssembly (WASM). Inside the downloaded .zip files, there are _b64.txt files which contain the binary model encoded with Base64. Copy the base64 strings and provide them as arguments to the RhinoWorkerFactory.create method.

Non-English Languages

Import { PicovoiceWorkerFactory } from the @picovoice/picovoice-web-xx-worker series of packages, where xx is the two-letter ISO language code:

import { PicovoiceWorkerFactory } from "@picovoice/picovoice-web-xx-worker";

Demo

For the Picovoice Web SDK, there is a Web demo project available on the Picovoice GitHub repository.

Setup

Clone the Picovoice repository from GitHub:

git clone --recurse-submodules https://github.com/Picovoice/picovoice.git

Usage

  1. Install dependencies and run:
cd picovoice/demo/web
npm install
npm run start
  1. Open http://localhost:5000 to view it in the browser.

Resources

Packages

API

GitHub

Benchmarks


Issue with this doc? Please let us know.