Made in Vancouver, Canada by Picovoice
Picovoice is an end-to-end platform for building voice products on your terms. It enables creating voice experiences similar to Alexa and Google. But it entirely runs 100% on-device. Picovoice is
First you will need Rust and Cargo installed on your system.
To add the picovoice library into your app, add picovoice
to your app's Cargo.toml
manifest:
toml
[dependencies]
picovoice = "*"
The Picovoice SDK requires a valid AccessKey
at initialization. AccessKey
s act as your credentials when using Picovoice SDKs.
You can create your AccessKey
for free. Make sure to keep your AccessKey
secret.
To obtain your AccessKey
:
1. Login or Signup for a free account on the Picovoice Console.
2. Once logged in, go to the AccessKey
tab to create one or use an existing AccessKey
.
To create an instance of the engine with default parameters, use the PicovoiceBuilder
function.
You must provide a Porcupine keyword file, a wake word detection callback function, a Rhino context file and a inference callback function.
You must then make a call to init()
:
```rust use picovoice::{rhino::RhinoInference, PicovoiceBuilder};
let accesskey = "${ACCESSKEY}"; // AccessKey obtained from Picovoice Console (https://picovoice.ai/console/)
let wakewordcallback = || { // let user know wake word detected }; let inferencecallback = |inference: RhinoInference| { if inference.isunderstood { let intent = inference.intent.unwrap(); let slots = inference.slots; // add code to take action based on inferred intent and slot values } else { // add code to handle unsupported commands } };
let mut picovoice = PicovoiceBuilder::new( accesskey, keywordpath, wakewordcallback, contextpath, inferencecallback, ).init().expect("Failed to create picovoice"); ```
Upon detection of wake word defined by keyword_path
it starts inferring user's intent
from the follow-on voice command within the context defined by the file located at context_path
.
keyword_path
is the absolute path to Porcupine wake word engine keyword file (with .ppn
suffix).
context_path
is the absolute path to Rhino Speech-to-Intent engine context file (with .rhn
suffix).
wake_word_callback
is invoked upon the detection of wake phrase and
inference_callback
isinvoked upon completion of follow-on voice command inference.
When instantiated, valid sample rate can be obtained via sample_rate()
.
Expected number of audio samples per frame is frame_length()
.
The engine accepts 16-bit linearly-encoded PCM and operates on single-channel audio.
```rust
fn nextaudioframe() -> Vec
loop { picovoice.process(&nextaudioframe()).expect("Picovoice failed to process audio"); } ```
The sensitivity of the Porcupine (wake word) and Rhino (inference) engines can be tuned
using the porcupine_sensitivity()
and rhino_sensitivity()
methods respectively.
They are floating point numbers within [0, 1].
A higher sensitivity value results in fewer misses at the cost of (potentially) increasing the erroneous inference rate:
```rust let accesskey = "${ACCESSKEY}"; // AccessKey obtained from Picovoice Console (https://picovoice.ai/console/)
let mut picovoice = PicovoiceBuilder::new( accesskey, keywordpath, wakewordcallback, contextpath, inferencecallback, ) .porcupinesensitivity(0.4f32) .rhinosensitivity(0.77f32) .init().expect("Failed to create picovoice"); ```
Non-standard model and library paths (For example, when using a non-english model) for both engines can be tuned in a similar manner:
```rust let accesskey = "${ACCESSKEY}"; // AccessKey obtained from Picovoice Console (https://picovoice.ai/console/)
let mut picovoice = PicovoiceBuilder::new( accesskey, keywordpath, wakewordcallback, contextpath, inferencecallback, ) .porcupinesensitivity(0.4f32) .rhinosensitivity(0.77f32) .porcupinemodelpath("path/to/model/params.pv") .rhinomodelpath("path/to/model/params.pv") .porcupinelibrarypath("path/to/library.so") .rhinolibrarypath("path/to/library.so") .init().expect("Failed to create picovoice"); ```
In order to detect wake words and run inference in other languages you need to use the corresponding model file. The model files for all supported languages are available here and here.
Check out the Picovoice Rust demos here