Made in Vancouver, Canada by Picovoice
Porcupine is a highly-accurate and lightweight wake word engine. It enables building always-listening voice-enabled applications. It is
First you will need Rust and Cargo installed on your system.
To add the porcupine library into your app, add pv_porcupine
to your apps Cargo.toml
manifest:
toml
[dependencies]
pv_porcupine = "1.9.1"
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:
toml
[dependencies]
pv_porcupine = { path = "/path/to/rust/binding" }
To create an instance of the engine you first create a PorcupineBuilder instance with the configuration parameters for the wake word engine and then make a call to .init()
.
```rust use porcupine::{BuiltinKeywords, PorcupineBuilder};
let porcupine: Porcupine = PorcupineBuilder::newwithkeywords(&[BuiltinKeywords::Porcupine]).init().expect("Unable to create Porcupine");
``
In the above example, we've initialzed the engine to detect the built-in wake word "Porcupine". Built-in keywords are contained in the package with the
BuiltinKeywords` enum type.
Porcupine can detect multiple keywords concurrently:
rust
let porcupine: Porcupine = PorcupineBuilder::new_with_keywords(&[BuiltinKeywords::Porcupine, BuiltinKeywords::Blueberry, BuiltinKeywords::Bumblebee])
.init().expect("Unable to create Porcupine");
To detect non-default keywords, use PorupineBuilder
's new_with_keyword_paths
method instead:
rust
let porcupine: Porcupine = PorcupineBuilder::new_with_keyword_paths(&["/absolute/path/to/keyword/one", "/absolute/path/to/keyword/two"])
.init().expect("Unable to create Porcupine");
The sensitivity of the engine can be tuned per keyword using the sensitivities
method:
rust
let porcupine: Porcupine = PorcupineBuilder::new_with_keywords(&[BuiltinKeywords::Porcupine, BuiltinKeywords::Bumblebee])
.sensitivities(&[0.2f32, 0.42f32])
.init().expect("Unable to create Porcupine");
Sensitivity is the parameter that enables trading miss rate for the false alarm rate. It is a floating point number within [0, 1]
. A higher sensitivity reduces the miss rate at the cost of increased false alarm rate.
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 Porcupine, use the process
function in your capture loop.
```rust
fn nextaudioframe() -> Vec
loop {
if let Ok(keywordindex) = porcupine.process(&nextaudioframe()) {
if keywordindex >= 0 {
// wake word detected!
}
}
}
```
In order to detect non-English wake words you need to use the corresponding model file. The model files for all supported languages are available here.
Check out the Porcupine Rust demos here