Rhino - NodeJS API
This document outlines how to integrate the Rhino Speech-to-Intent engine within an NodeJS application.
Requirements
- NodeJS 10+
- yarn (or npm)
Compatibility
- Linux (x86_64)
- macOS (x86_64)
- Raspberry Pi (2,3,4)
Web Browsers
Looking to run Picovoice in-browser? See the JavaScript WebAssembly demo instead.
Installation
yarn add @picovoice/rhino-node
or
npm install @picovoice/rhino-node
Usage
The Rhino SDK for NodeJS provides the Rhino
class. Here is an example using the sample "Coffee Maker" context file:
const Rhino = require("@picovoice/rhino-node")const coffeeMakerContextPath = "./coffee_maker.rhn"let handle = new Rhino(coffeeMakerContextPath)let isFinalized = false// process each frame of audio until Rhino has concluded that it understood the phrase (or did not)// when Rhino has reached a conclusion, isFinalized will become truewhile (!isFinalized) {isFinalized = handle.process(frame)// retrieve the inference from Rhinoif (isFinalized) {let inference = handle.getInference()// inference result example://// {// isUnderstood: true,// intent: 'orderDrink',// slots: {// size: 'medium',// numberOfShots: 'double shot',// coffeeDrink: 'americano',// milkAmount: 'lots of milk',// sugarAmount: 'some sugar'// }// }}}// always call release when finished to free the resources allocated by Rhinohandle.release()
Override model and library paths
The Rhino constructor accepts three optional positional parameters for the sensitivity and the absolute paths to the model and dynamic library, should you need to override them (typically, you will not).
let handle = new Rhino(contextPath, sensitivity, modelFilePath, libraryFilePath)
Custom Context
You can create custom Rhino context models using Picovoice Console.