Picovoice Platform
Rust API
API Reference for the Picovoice Rust SDK (crates.io).
picovoice::Picovoice
Struct for the Picovoice Platform.
picovoice::Picovoice::new()
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_endpoint_duration_sec
Option<f32> : Endpoint duration in seconds. An endpoint is a chunk of silence at the end of an utterance that marks the end of spoken command. It should be a positive number within [0.5, 5]. A lower endpoint duration reduces delay and improves responsiveness. A higher endpoint duration assures Rhino doesn't return inference pre-emptively in case the user pauses before finishing the request.rhino_require_endpoint
bool : If set totrue
, Rhino requires an endpoint (a chunk of silence) after the spoken command. If set tofalse
, Rhino tries to detect silence, but if it cannot, it still will provide inference regardless. Set tofalse
only if operating in an environment with overlapping speech (e.g. people talking in the background).
Returns
Result<Picovoice, PicovoiceError>
: IfOk
, an instance ofPicovoice
struct. IfErr
, aPicovoiceError
describing the error that was encountered.
picovoice::Picovoice.process()
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>
: IfOk
, nothing is returned. IfErr
, aPicovoiceError
describing the error that was encountered.
picovoice::Picovoice.reset()
Resets the internal state of Picovoice. It should be called before processing a new stream of audio or when Picovoice was stopped while processing a stream of audio.
Returns
Result<(), PicovoiceError>
: IfOk
, nothing is returned. IfErr
, aPicovoiceError
describing the error that was encountered.
picovoice::Picovoice.frame_length()
Gets the required frame length.
Returns
u32
: Number of audio samples per frame.
picovoice::Picovoice.sample_rate()
Gets the required sample rate.
Returns
u32
: Audio sample rate accepted by Picovoice.
picovoice::Picovoice.version()
Gets the Picovoice version.
Returns
String
: Picovoice version string.
picovoice::PicovoiceBuilder
Builder class for creating an instance of Picovoice
.
picovoice::PicovoiceBuilder::new()
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
PicovoiceBuilder
: A new Builder object.
picovoice::PicovoiceBuilder.porcupine_library_path()
Overrides the default porcupine_library_path
of a PicovoiceBuilder
object.
Parameters
porcupine_library_path
P : Absolute path to the Porcupine library.
Returns
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.porcupine_model_path()
Overrides the default porcupine_model_path
of a PicovoiceBuilder
object.
Parameters
porcupine_model_path
P : Path to Porcupine model file (.pv
).
Returns
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.porcupine_sensitivity()
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
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.rhino_library_path()
Overrides the default rhino_library_path
of a PicovoiceBuilder
object.
Parameters
rhino_library_path
P : Absolute path to the Rhino library.
Returns
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.rhino_model_path()
Overrides the default rhino_model_path
of a PicovoiceBuilder
object.
Parameters
rhino_model_path
P : Path to Rhino model file (.pv
).
Returns
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.rhino_sensitivity()
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
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.rhino_endpoint_duration_sec()
Overrides the default rhino_endpoint_duration_sec
of a PicovoiceBuilder
object.
Parameters
rhino_endpoint_duration_sec
f32 : Endpoint duration in seconds. An endpoint is a chunk of silence at the end of an utterance that marks the end of spoken command. It should be a positive number within [0.5, 5]. A lower endpoint duration reduces delay and improves responsiveness. A higher endpoint duration assures Rhino doesn't return inference pre-emptively in case the user pauses before finishing the request.
Returns
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.rhino_require_endpoint()
Overrides the default value of rhino_require_endpoint
in a PicovoiceBuilder
object.
Parameters
rhino_require_endpoint
bool : If set totrue
, Rhino requires an endpoint (a chunk of silence) after the spoken command. If set tofalse
, Rhino tries to detect silence, but if it cannot, it still will provide inference regardless. Set tofalse
only if operating in an environment with overlapping speech (e.g. people talking in the background).
Returns
PicovoiceBuilder
: The modified Builder object.
picovoice::PicovoiceBuilder.init()
Creates an instance of Picovoice
from the PicovoiceBuilder
object.
Returns
Result<Picovoice<W, I>, PicovoiceError>
: IfOk
, an initialized instance ofPicovoice
. IfErr
, and instance ofPicovoiceError
detailing the error that was encountered.
picovoice::PicovoiceError
An error type describing errors produced by the Picovoice Rust SDK.