Crates.io | pv_rhino |
lib.rs | pv_rhino |
version | 3.0.3 |
source | src |
created_at | 2021-08-11 18:05:39.801884 |
updated_at | 2024-08-15 19:13:11.324715 |
description | The Rust bindings for Picovoice's Rhino library |
homepage | https://picovoice.ai/platform/rhino/ |
repository | https://github.com/Picovoice/rhino |
max_upload_size | |
id | 434886 |
size | 4,191,977 |
Made in Vancouver, Canada by Picovoice
Rhino is Picovoice's Speech-to-Intent engine. It directly infers intent from spoken commands within a given context of interest, in real-time. For example, given a spoken command:
Can I have a small double-shot espresso?
Rhino infers that the user would like to order a drink and emits the following inference result:
{
"isUnderstood": "true",
"intent": "orderBeverage",
"slots": {
"beverage": "espresso",
"size": "small",
"numberOfShots": "2"
}
}
Rhino is:
First you will need Rust and Cargo installed on your system.
To add the rhino library into your app, add pv_rhino
to your apps Cargo.toml
manifest:
[dependencies]
pv_rhino = "*"
If you prefer to clone the repo and use it locally, first run copy.sh
.
(NOTE: on Windows, Git Bash or another bash shell is required, or you will have to manually copy the libs into the project).
Then you can reference the local binding location:
[dependencies]
pv_rhino = { path = "/path/to/rust/binding" }
Rhino requires a valid Picovoice AccessKey
at initialization. AccessKey
acts as your credentials when using Rhino SDKs.
You can get your AccessKey
for free. Make sure to keep your AccessKey
secret.
Signup or Login to Picovoice Console to get your AccessKey
.
To create an instance of the engine you first create a RhinoBuilder
instance with the configuration parameters for the speech to intent engine and then make a call to .init()
:
use rhino::RhinoBuilder;
let access_key = "${ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
let rhino: Rhino = RhinoBuilder::new(access_key, "/path/to/context/file.rhn").init().expect("Unable to create Rhino");
The context file is a Speech-to-Intent context created either using Picovoice Console or one of the default contexts available on Rhino's GitHub repository.
The sensitivity of the engine can be tuned using the sensitivity
parameter.
It is a floating-point number within [0, 1].
A higher sensitivity value results in fewer misses at the cost of (potentially) increasing the erroneous inference rate.
You can also override the default Rhino model (.pv), which is needs to be done when using a non-English context:
let rhino: Rhino = RhinoBuilder::RhinoBuilder::new(access_key, "/path/to/context/file.rhn")
.sensitivity(0.42f32)
.model_path("/path/to/rhino/params.pv")
.init().expect("Unable to create Rhino");
When initialized, the valid sample rate is given by sample_rate()
.
Expected frame length (number of audio samples in an input array) is given by frame_length()
.
The engine accepts 16-bit linearly-encoded PCM and operates on single-channel audio.
To feed audio into Rhino, use the process
function in your capture loop:
fn next_audio_frame() -> Vec<i16> {
// get audio frame
}
loop {
if let Ok(is_finalized) = rhino.process(&next_audio_frame()) {
if is_finalized {
if let Ok(inference) = rhino.get_inference() {
if inference.is_understood {
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
}
}
}
}
}
In order to detect non-English contexts you need to use the corresponding model file. The model files for all supported languages are available here.
Check out the Rhino Rust demos here