wasmOctopus - 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 Octopus Web Worker package:

npm install @picovoice/octopus-web-en-worker

Usage

Create an OctopusWorker:

import { OctopusWorkerFactory } from "@picovoice/octopus-web-en-worker";
// The metadata object to save the result of indexing for later searches
let octopusMetadata = undefined;
function octopusIndexCallback(metadata) {
octopusMetadata = metadata;
}
function octopusSearchCallback(matches) {
console.log(`Search results (${matches.length}):`);
matches.forEach((match) => {
console.log(`Start: ${match.startSec}s -> End: ${match.endSec}s (Probability: ${match.probability})`);
});
}
const octopusWorker = await OctopusWorkerFactory.create(
"${ACCESS_KEY}",
octopusIndexCallback,
octopusSearchCallback
);

Index raw audio data (sample rate of 16 kHz, 16-bit linearly encoded and 1 channel):

const audioData = new Int16Array(/* ${AUDIO_DATA} */);
octopusWorker.postMessage({
command: "index",
input: audioData,
});

Search for instances of a phrase:

const searchText = "${SEARCH_PHRASE}";
OctopusWorker.postMessage({
command: "search",
metadata: octopusMetadata,
searchPhrase: searchText,
});

Release resources explicitly when done with Octopus:

octopusWorker.sendMessage({ command: "release" });

Demo

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

Setup

Clone the Octopus repository from GitHub:

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

Usage

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

Resources

Packages

API

GitHub

Benchmark


Issue with this doc? Please let us know.