rustPicovoice Platform — Rust API

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


picovoice::Picovoice

pub struct Picovoice<W, I>
where
W: FnMut(),
I: FnMut(RhinoInference),

Struct for the Picovoice Platform.


picovoice::Picovoice::new()

pub fn new<S: Into<String>, P: Into<PathBuf>>(
access_key: S,
keyword_path: P,
wake_word_callback: W,
context_path: P,
inference_callback: I,
porcupine_library_path: Option<P>,
porcupine_model_path: Option<P>,
porcupine_sensitivity: Option<f32>,
rhino_library_path: Option<P>,
rhino_model_path: Option<P>,
rhino_sensitivity: Option<f32>,
rhino_require_endpoint: bool
) -> Result<Self, PicovoiceError>

Creates a new instance of Picovoice.

Parameters

  • access_key S : AccessKey obtained from Picovoice Console.
  • keyword_path P : Absolute path to Porcupine keyword file (.ppn).
  • wake_word_callback W : Function to be called once the wake word has been detected.
  • context_path P : Absolute path to the Rhino context file (.rhn).
  • inference_callback I : Function to be called once Rhino has an inference ready.
  • porcupine_library_path Option<P> : Absolute path to the Porcupine library.
  • porcupine_model_path Option<P> : Path to Porcupine model file (.pv).
  • porcupine_sensitivity Option<f32> : Sensitivity value for detecting keyword. The value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
  • rhino_library_path Option<P> : Absolute path to the Rhino library.
  • rhino_model_path Option<P> : Path to Rhino model file (.pv).
  • rhino_sensitivity Option<f32> : Inference sensitivity. A higher sensitivity value results in fewer misses at the cost of (potentially) increasing the erroneous inference rate. Sensitivity should be a floating-point number within 0 and 1.
  • rhino_require_endpoint bool : If set to false, Rhino does not require an endpoint (chunk of silence) before finishing inference.

Returns

  • Result<Picovoice, PicovoiceError> : If Ok, an instance of Picovoice struct. If Err, a PicovoiceError describing the error that was encountered.

picovoice::Picovoice.process()

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

Process a frame of pcm audio with the Picovoice platform. Invokes user-defined callbacks upon detection of wake word and completion of follow-on command inference.

Parameters

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

Returns

  • Result<(), PicovoiceError> : If Ok, nothing is returned. If Err, a PicovoiceError describing the error that was encountered.

picovoice::Picovoice.frame_length()

pub fn frame_length(&self) -> u32

Gets the required frame length.

Returns

  • u32 : Number of audio samples per frame.

picovoice::Picovoice.sample_rate()

pub fn sample_rate(&self) -> u32

Gets the required sample rate.

Returns

  • u32 : Audio sample rate accepted by Picovoice.

picovoice::Picovoice.version()

pub fn version(&self) -> String

Gets the Picovoice version.

Returns

  • String : Picovoice version string.

picovoice::PicovoiceBuilder

pub struct PicovoiceBuilder<W, I>
where
W: FnMut(),
I: FnMut(RhinoInference),

Builder class for creating an instance of Picovoice.


picovoice::PicovoiceBuilder::new()

pub fn new<S: Into<String>, P: Into<PathBuf>>(
access_key: S,
keyword_path: P,
wake_word_callback: W,
context_path: P,
inference_callback: I
) -> Self

Creates a new instance of PicovoiceBuilder.

Parameters

  • access_key S : AccessKey obtained from Picovoice Console.
  • keyword_path P : Absolute path to Porcupine keyword file (.ppn).
  • wake_word_callback W : Function to be called once the wake word has been detected.
  • context_path P : Absolute path to the Rhino context file (.rhn).
  • inference_callback I : Function to be called once Rhino has an inference ready.

Returns


picovoice::PicovoiceBuilder.porcupine_library_path()

pub fn porcupine_library_path<P: Into<PathBuf>>(
self,
porcupine_library_path: P
) -> Self

Overrides the default porcupine_library_path of a PicovoiceBuilder object.

Parameters

  • porcupine_library_path P : Absolute path to the Porcupine library.

Returns


picovoice::PicovoiceBuilder.porcupine_model_path()

pub fn porcupine_model_path<P: Into<PathBuf>>(
self,
porcupine_model_path: P
) -> Self

Overrides the default porcupine_model_path of a PicovoiceBuilder object.

Parameters

  • porcupine_model_path P : Path to Porcupine model file (.pv).

Returns


picovoice::PicovoiceBuilder.porcupine_sensitivity()

pub fn porcupine_sensitivity(self, porcupine_sensitivity: f32) -> Self

Overrides the default porcupine_sensitivity of a PicovoiceBuilder object.

Parameters

  • porcupine_sensitivity f32 : Sensitivity value for detecting keyword. The value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.

Returns


picovoice::PicovoiceBuilder.rhino_library_path()

pub fn rhino_library_path<P: Into<PathBuf>>(self, rhino_library_path: P) -> Self

Overrides the default rhino_library_path of a PicovoiceBuilder object.

Parameters

  • rhino_library_path P : Absolute path to the Rhino library.

Returns


picovoice::PicovoiceBuilder.rhino_model_path()

pub fn rhino_model_path<P: Into<PathBuf>>(self, rhino_model_path: P) -> Self

Overrides the default rhino_model_path of a PicovoiceBuilder object.

Parameters

  • rhino_model_path P : Path to Rhino model file (.pv).

Returns


picovoice::PicovoiceBuilder.rhino_sensitivity()

pub fn rhino_sensitivity(self, rhino_sensitivity: f32) -> Self

Overrides the default rhino_sensitivity of a PicovoiceBuilder object.

Parameters

  • rhino_sensitivity f32 : Inference sensitivity. A higher sensitivity value results in fewer misses at the cost of (potentially) increasing the erroneous inference rate. Sensitivity should be a floating-point number within 0 and 1.

Returns


picovoice::PicovoiceBuilder.rhino_require_endpoint()

pub fn rhino_require_endpoint(self, rhino_require_endpoint: bool) -> Self

Overrides the default value of rhino_require_endpoint in a PicovoiceBuilder object.

Parameters

  • rhino_require_endpoint bool : If set to false, Rhino does not require an endpoint (chunk of silence) before finishing inference. Default value is true.

Returns


picovoice::PicovoiceBuilder.init()

pub fn init(self) -> Result<Picovoice<W, I>, PicovoiceError>

Creates an instance of Picovoice from the PicovoiceBuilder object.

Returns

  • Result<Picovoice<W, I>, PicovoiceError> : If Ok, an initialized instance of Picovoice. If Err, and instance of PicovoiceError detailing the error that was encountered.

picovoice::PicovoiceError

pub enum PicovoiceError {
RhinoError(RhinoError),
PorcupineError(PorcupineError),
LibraryError(String),
}

An error type describing errors produced by the Picovoice Rust SDK.


Issue with this doc? Please let us know.