rustPorcupine - Rust API

API Reference for the Porcupine Rust SDK (crates.io).


porcupine::BuiltInKeywords

pub enum BuiltinKeywords {
Alexa,
Americano,
Blueberry,
Bumblebee,
Computer,
Grapefruit,
Grasshopper,
HeyGoogle,
HeySiri,
Jarvis,
OkGoogle,
Picovoice,
Porcupine,
Terminator,
}

List of available built-in wake words.


porcupine::Porcupine

pub struct Porcupine

Struct for the Porcupine Wake Word engine.


porcupine::Porcupine.frame_length()

pub fn frame_length(&self) -> u32

Number of audio samples per frame.

Returns

  • u32 : Frame length required by the engine.

porcupine::Porcupine.sample_rate()

pub fn sample_rate(&self) -> u32

Audio sample rate accepted by Porcupine.

Returns

  • u32 : Sample rate required by the engine.

porcupine::Porcupine.version()

pub fn version(&self) -> String

Porcupine version.

Returns

  • String : Version string.

porcupine::Porcupine.process()

pub fn process(&self, pcm: &[i16]) -> Result<i32, PorcupineError>

Processes a frame of the incoming audio stream and emits the detection result. Frame of audio The number of samples-per-frame can be obtained by calling .frame_length. The incoming audio needs to have a sample rate equal to .sample_rate and be 16-bit linearly-encoded. Porcupine operates on single-channel audio. Returns a 0 based index if keyword was detected in frame. Returns -1 if no detection was made.

Parameters

  • pcm &[i16] : A frame of audio samples.

Returns

  • Result<i32, PorcupineError> : If Ok, Index of observed keyword at the end of the current frame. Indexing is 0-based and matches the ordering of keywords provided to the Porcupine struct. If no keyword is detected then it returns -1. If Err, a PorcupineError.

porcupine::PorcupineBuilder

pub struct PorcupineBuilder

Builder class for creating an instance of Porcupine with a variety of properties.


porcupine::PorcupineBuilder::new_with_keywords()

pub fn new_with_keywords<S: Into<String>>(
access_key: S,
keywords: &[BuiltinKeywords]
) -> Self

Creates a PorcupineBuilder from built-in keywords.

Parameters

  • access_key S : AccessKey obtained from Picovoice Console.
  • keywords &[BuiltinKeywords] : Built-in keywords to detect.

Returns


porcupine::PorcupineBuilder::new_with_keyword_paths()

pub fn new_with_keyword_paths<S: Into<String>, P: Into<PathBuf> + AsRef<OsStr>>(
access_key: S,
keyword_paths: &[P]
) -> Self

Creates a PorcupineBuilder from Porcupine keyword files.

Parameters

  • access_key S : AccessKey obtained from Picovoice Console.
  • keyword_paths &[P] : Paths to Porcupine keyword files (.ppn).

Returns


porcupine::PorcupineBuilder.access_key()

pub fn access_key<'a, S: Into<String>>(
&'a mut self,
access_key: S
) -> &'a mut Self

Modifies the access_key of a PorcupineBuilder object.

Parameters

Returns


porcupine::PorcupineBuilder.library_path()

pub fn library_path<'a, P: Into<PathBuf>>(
&'a mut self,
library_path: P
) -> &'a mut Self

Overrides the default library_path of a PorcupineBuilder object.

Parameters

  • library_path P : Path to the Porcupine library file.

Returns


porcupine::PorcupineBuilder.model_path()

pub fn model_path<'a, P: Into<PathBuf>>(
&'a mut self,
model_path: P
) -> &'a mut Self

Overrides the default model_path of a PorcupineBuilder object.

Parameters

  • model_path P : Path to the file containing model parameters (.pv).

Returns


porcupine::PorcupineBuilder.keyword_paths()

pub fn keyword_paths<'a, P: Into<PathBuf> + AsRef<OsStr>>(
&'a mut self,
keyword_paths: &[P]
) -> &'a mut Self

Modifies the keyword_paths of a PorcupineBuilder object.

Parameters

  • keyword_paths &[P] : Paths to Porcupine keyword files (.ppn).

Returns


porcupine::PorcupineBuilder.sensitivities()

pub fn sensitivities<'a>(&'a mut self, sensitivities: &[f32]) -> &'a mut PorcupineBuilder

Overrides the default sensitivities of a PorcupineBuilder object. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate. This should be the same size as the number of keywords. If not set, values of 0.5 are used.

Parameters

  • sensitivities &[f32] : Sensitivities for detecting keywords.

Returns


porcupine::PorcupineBuilder.init()

pub fn init(&self) -> Result<Porcupine, PorcupineError>

Creates an instance of Porcupine from the PorcupineBuilder object.

Returns

  • Result<Porcupine, PorcupineError> : If Ok, an initialized instance of Porcupine. If Err, and instance of PorcupineError detailing the error that was encountered.

porcupine::PorcupineError

pub struct PorcupineError

An error type describing any errors encountered by the Porcupine SDK.


porcupine::PorcupineError.status

pub status: PorcupineErrorStatus

Type of error encountered.


porcupine::PorcupineError.message

pub status: Option<String>

Message detailing the cause of the error.


porcupine::PorcupineError::new()

pub fn new(status: PorcupineErrorStatus, message: &str) -> Self

Creates a new instance of PorcupineError.

Parameters

  • status PorcupineErrorStatus : Type of error encountered.
  • message &str : Message detailing the cause of the error.

porcupine::PorcupineErrorStatus

pub enum PorcupineErrorStatus {
LibraryError(PvStatus),
LibraryLoadError,
FrameLengthError,
ArgumentError,
}

Enum describing possible error types returned from the Porcupine Rust SDK.


porcupine::PvStatus

pub enum PvStatus {
SUCCESS,
OUT_OF_MEMORY,
IO_ERROR,
INVALID_ARGUMENT,
STOP_ITERATION,
KEY_ERROR,
INVALID_STATE,
RUNTIME_ERROR,
ACTIVATION_ERROR,
ACTIVATION_LIMIT_REACHED,
ACTIVATION_THROTTLED,
ACTIVATION_REFUSED,
}

Error codes returned from the Porcupine library.


Issue with this doc? Please let us know.