Rhino - 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 Rhino Web Worker packages:
npm install @picovoice/rhino-web-en-worker @picovoice/web-voice-processor
Usage
Create a RhinoWorker
using either a pre-trained context file (.rhn
) from the
Rhino GitHub Repository or a
custom context created with the Picovoice Console:
import { RhinoWorkerFactory } from "@picovoice/rhino-web-en-worker";const contextFileBase64 = // base64 of Rhino context file (.rhn)const rhinoWorker = await RhinoWorkerFactory.create({accessKey: "${ACCESS_KEY}",context: {base64: contextFileBase64}},);rhinoWorker.onmessage = (msg) => {if (msg.data.command === '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}}};
Initialize and Start the Web Voice Processor to pass audio to the Rhino engine:
import { WebVoiceProcessor } from "@picovoice/web-voice-processor"const webVoiceProcessor = await WebVoiceProcessor.init({engines: [rhinoWorker]});webVoiceProcessor.start();
Pause with:
webVoiceProcessor.pause();
Release resources explicitly when done with Rhino:
webVoiceProcessor.release()rhinoWorker.sendMessage({command: "release"})
Custom Contexts
Create custom contexts using the Picovoice Console.
Train the Rhino context 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
RhinoWorkerFactory.create
method.
Non-English Languages
Import { RhinoWorkerFactory }
from the @picovoice/rhino-web-xx-worker
series of packages, where xx
is
the two-letter ISO language code:
import { RhinoWorkerFactory } from "@picovoice/rhino-web-xx-worker";
Demo
For the Rhino Web SDK, there is a Web demo project available on the Rhino GitHub repository.
Setup
Clone the Rhino repository from GitHub:
git clone --recurse-submodules https://github.com/Picovoice/rhino.git
Usage
- Install dependencies and run:
cd rhino/demo/webnpm installnpm run start
- Open http://localhost:5000 to view it in the browser.
Resources
Packages
- @picovoice/rhino-web-en-worker
- @picovoice/rhino-web-de-worker
- @picovoice/rhino-web-es-worker
- @picovoice/rhino-web-fr-worker
- @picovoice/web-voice-processor