Picovoice WordmarkPicovoice Console
Introduction
Introduction
AndroidC.NETFlutterlink to GoiOSJavaNvidia JetsonLinuxmacOSNodejsPythonRaspberry PiReact NativeRustWebWindows
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
SummaryPicovoice LeopardAmazon TranscribeAzure Speech-to-TextGoogle ASRGoogle ASR (Enhanced)IBM Watson Speech-to-Text
FAQ
Introduction
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
FAQ
Introduction
AndroidCiOSLinuxmacOSPythonWebWindows
AndroidCiOSPythonWeb
SummaryOctopus Speech-to-IndexGoogle Speech-to-TextMozilla DeepSpeech
FAQ
Introduction
AndroidAngularArduinoBeagleBoneCChrome.NETEdgeFirefoxFlutterlink to GoiOSJavaNvidia JetsonLinuxmacOSMicrocontrollerNodejsPythonRaspberry PiReactReact NativeRustSafariUnityVueWebWindows
AndroidAngularC.NETFlutterlink to GoiOSJavaMicrocontrollerNodejsPythonReactReact NativeRustUnityVueWeb
SummaryPorcupineSnowboyPocketSphinx
Wake Word TipsFAQ
Introduction
AndroidAngularBeagleBoneCChrome.NETEdgeFirefoxFlutterlink to GoiOSJavaNvidia JetsonlinuxmacOSNodejsPythonRaspberry PiReactReact NativeRustSafariUnityVueWebWindows
AndroidAngularC.NETFlutterlink to GoiOSJavaNodejsPythonReactReact NativeRustUnityVueWeb
SummaryPicovoice RhinoGoogle DialogflowAmazon LexIBM WatsonMicrosoft LUIS
Expression SyntaxFAQ
Introduction
AndroidBeagleboneCiOSNvidia JetsonLinuxmacOSPythonRaspberry PiRustWebWindows
AndroidCiOSPythonRustWeb
SummaryPicovoice CobraWebRTC VAD
FAQ
Introduction
AndroidCiOSPythonWeb
AndroidCiOSPythonWeb
SummaryPicovoice KoalaMozilla RNNoise
Introduction
AndroidAngularArduinoBeagleBoneC.NETFlutterlink to GoiOSJavaNvidia JetsonMicrocontrollerNodejsPythonRaspberry PiReactReact NativeRustUnityVueWeb
AndroidAngularCMicrocontroller.NETFlutterlink to GoiOSJavaNodejsPythonReactReact NativeRustUnityVueWeb
Picovoice SDK - FAQ
IntroductionSTM32F407G-DISC1 (Arm Cortex-M4)STM32F411E-DISCO (Arm Cortex-M4)STM32F769I-DISCO (Arm Cortex-M7)IMXRT1050-EVKB (Arm Cortex-M7)
FAQGlossary

Porcupine Wake Word — 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

  • PorcupineBuilder : A new Builder object.

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

  • PorcupineBuilder : A new Builder object.

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

  • access_key S : AccessKey obtained from Picovoice Console .

Returns

  • PorcupineBuilder : The modified Builder object.

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

  • PorcupineBuilder : The modified Builder object.

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

  • PorcupineBuilder : The modified Builder object.

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

  • PorcupineBuilder : The modified Builder object.

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

  • PorcupineBuilder : The modified Builder object.

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.

Was this doc helpful?

Issue with this doc?

Report a GitHub Issue
Porcupine Wake Word — Rust API
  • porcupine::BuiltInKeywords
  • porcupine::Porcupine
  • frame_length()
  • sample_rate()
  • version()
  • process()
  • porcupine::PorcupineBuilder
  • porcupine::PorcupineBuilder::new_with_keywords()
  • porcupine::PorcupineBuilder::new_with_keyword_paths()
  • access_key()
  • library_path()
  • model_path()
  • keyword_paths()
  • sensitivities()
  • init()
  • porcupine::PorcupineError
  • status
  • message
  • porcupine::PorcupineError::new()
  • porcupine::PorcupineErrorStatus
  • porcupine::PvStatus
Platform
  • Leopard Speech-to-Text
  • Cheetah Streaming Speech-to-Text
  • Octopus Speech-to-Index
  • Porcupine Wake Word
  • Rhino Speech-to-Intent
  • Cobra Voice Activity Detection
Resources
  • Docs
  • Console
  • Blog
  • Demos
Sales
  • Pricing
  • Starter Tier
  • Enterprise
Company
  • Careers
Follow Picovoice
  • LinkedIn
  • GitHub
  • Twitter
  • Medium
  • YouTube
  • AngelList
Subscribe to our newsletter
Terms of Use
Privacy Policy
© 2019-2022 Picovoice Inc.