Porcupine - Web Quick Start
Platforms
- Chrome & Chromium-based browsers
- Edge
- Firefox
- Safari
Requirements
- Picovoice Account and AccessKey
- Node.js 12+
- 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 Web Voice Processor and Porcupine Web Worker packages:
npm install @picovoice/porcupine-web-en-worker @picovoice/web-voice-processor
Usage
Create a PorcupineWorker
that detects the included built-in wake words porcupine
and bumblebee
:
import { PorcupineWorkerFactory } from "@picovoice/porcupine-web-en-worker";function keywordCallback(keyword) {console.log(`Porcupine detected ${keyword}`);}const porcupineWorker = await PorcupineWorkerFactory.create("${ACCESS_KEY}",[{builtin: "Porcupine"}, {builtin: "Bumblebee"}],keywordCallback,);
Initialize and start the Web Voice Processor to pass audio to the Porcupine engine:
import { WebVoiceProcessor } from "@picovoice/web-voice-processor"const webVoiceProcessor = await WebVoiceProcessor.init({engines: [porcupineWorker]});webVoiceProcessor.start();
Release resources explicitly when done with Porcupine:
webVoiceProcessor.release()porcupineWorker.sendMessage({command: "release"})
Custom Keywords
Create custom keywords using the Picovoice Console.
Train the Porcupine keyword model for the target platform WebAssembly (WASM).
Inside the downloaded .zip
file, there is a _b64.txt
file which contains the binary model
encoded with Base64. Copy the base64 string and provide it as an argument to the
PorcupineWorkerFactory.create
method:
const porcupineWorker = await PorcupineWorkerFactory.create("${ACCESS_KEY}",[{custom: "${CUSTOM_KEYWORD_LABEL}",base64: "${CUSTOM_KEYWORD_BASE64_STRING}"}],keywordCallback);
Non-English Languages
Import { PorcupineWorkerFactory }
from the @picovoice/porcupine-web-xx-worker
series of packages, where xx
is
the two-letter ISO language code:
import { PorcupineWorkerFactory } from "@picovoice/porcupine-web-xx-worker";
Demo
For the Porcupine Web SDK, there is a Web demo project available on the Porcupine GitHub repository.
Setup
Clone the Porcupine repository from GitHub:
git clone --recurse-submodules https://github.com/Picovoice/porcupine.git
Usage
- Install dependencies and run:
cd porcupine/demo/webnpm installnpm run start
- Open http://localhost:5000 to view it in the browser.
Resources
Packages
- @picovoice/porcupine-web-en-worker
- @picovoice/porcupine-web-de-worker
- @picovoice/porcupine-web-es-worker
- @picovoice/porcupine-web-fr-worker
- @picovoice/web-voice-processor