Porcupine Wake Word
Rust API
API Reference for the Porcupine Rust SDK (crates.io).
porcupine::BuiltInKeywords
List of available built-in wake words.
porcupine::Porcupine
Struct for the Porcupine Wake Word engine.
porcupine::Porcupine.frame_length()
Number of audio samples per frame.
Returns
u32
: Frame length required by the engine.
porcupine::Porcupine.sample_rate()
Audio sample rate accepted by Porcupine.
Returns
u32
: Sample rate required by the engine.
porcupine::Porcupine.version()
Porcupine version.
Returns
String
: Version string.
porcupine::Porcupine.process()
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>
: IfOk
, 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. IfErr
, aPorcupineError
.
porcupine::PorcupineBuilder
Builder class for creating an instance of Porcupine
with a variety of properties.
porcupine::PorcupineBuilder::new_with_keywords()
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()
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()
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()
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()
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()
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()
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()
Creates an instance of Porcupine
from the PorcupineBuilder
object.
Returns
Result<Porcupine, PorcupineError>
: IfOk
, an initialized instance ofPorcupine
. IfErr
, and instance ofPorcupineError
detailing the error that was encountered.
porcupine::PorcupineError
An error type describing any errors encountered by the Porcupine SDK.
porcupine::PorcupineError.status
Type of error encountered.
porcupine::PorcupineError.message
Message detailing the cause of the error.
porcupine::PorcupineError::new()
Creates a new instance of PorcupineError
.
Parameters
status
PorcupineErrorStatus
: Type of error encountered.message
&str : Message detailing the cause of the error.
porcupine::PorcupineErrorStatus
Enum describing possible error types returned from the Porcupine Rust SDK.
porcupine::PvStatus
Error codes returned from the Porcupine library.