Leopard - Rust API
API Reference for the Leopard Rust SDK (crates.io).
leopard::Leopard
pub struct Leopard
Struct for the Leopard Speech-to-Text engine.
leopard::Leopard.process()
pub fn process(&self, pcm: &[i16]) -> Result<String, LeopardError>
Processes a given audio data and returns its transcription. The audio needs to have a sample
rate equal to .sample_rate
and be 16-bit linearly-encoded. This function operates on single-channel audio.
If you wish to process data in a different sample rate or format consider using .process_file()
.
Parameters
pcm
&[i16] : Audio data.
Returns
Result<String, LeopardError>
: IfOk
, returns the inferred transcription. IfErr
, aLeopardError
object describing the error that was encountered.
leopard::Leopard.process_file()
pub fn process_file<P: AsRef<Path>>(&self, audio_path: P) -> Result<String, LeopardError>
Processes a given audio file and returns its transcription. The file needs to have a sample rate equal to or
greater than .sample_rate
.
The supported audio file formats are: FLAC
, MP3
, Ogg
, Opus
, Vorbis
, WAV
, and WebM
.
Parameters
audio_path
P : Absolute path to the audio file.
Returns
Result<String, LeopardError>
: IfOk
, returns the inferred transcription. IfErr
, aLeopardError
object describing the error that was encountered.
leopard::Leopard.sample_rate()
pub fn sample_rate(&self) -> u32
Gets the sample rate.
Returns
u32
: Audio sample rate accepted by Leopard.
leopard::Leopard.version()
pub fn version(&self) -> &str
Gets the Leopard version.
Returns
&str
: Leopard version string.
leopard::LeopardBuilder
pub struct LeopardBuilder
Builder struct for creating an instance of Leopard
.
leopard::LeopardBuilder.new()
pub fn new<S: Into<String>>(access_key: S) -> Self
Creates a new LeopardBuilder
from required arguments.
Parameters
access_key
S : AccessKey obtained from Picovoice Console.
Returns
LeopardBuilder
: A new Builder object.
leopard::LeopardBuilder.access_key()
pub fn access_key<S: Into<String>>(&mut self, access_key: S) -> &mut Self
Modifies the access_key
of a LeopardBuilder
object.
Parameters
access_key
S : AccessKey obtained from Picovoice Console.
Returns
LeopardBuilder
: The modified Builder object.
leopard::LeopardBuilder.library_path()
pub fn library_path<P: Into<PathBuf>>(&mut self, library_path: P) -> &mut Self
Modifies the library_path
of a LeopardBuilder
object.
Parameters
library_path
P : Path to the Leopard library file.
Returns
LeopardBuilder
: The modified Builder object.
leopard::LeopardBuilder.model_path()
pub fn model_path<P: Into<PathBuf>>(&mut self, model_path: P) -> &mut Self
Modifies the model_path
of a LeopardBuilder
object.
Parameters
model_path
P : Path to the file containing model parameters (.pv
).
Returns
LeopardBuilder
: The modified Builder object.
leopard::LeopardBuilder.init()
pub fn init(&self) -> Result<Leopard, LeopardError>
Creates an instance of Leopard
from the LeopardBuilder
object.
Returns
Result<Leopard, LeopardError>
: IfOk
, an initialized instance ofLeopard
. IfErr
, an instance ofLeopardError
detailing the error that was encountered.
leopard::LeopardError
pub struct LeopardError
An error type describing any errors encountered by the Leopard SDK.
leopard::LeopardError.new()
pub fn new(status: LeopardErrorStatus, message: impl Into<String>) -> Self
Creates a new instance of LeopardError
Parameters
status
LeopardErrorStatus
: Type of error encountered.message
impl Into<String> : Message detailing the cause of the error.
leopard::LeopardErrorStatus
pub enum LeopardErrorStatus {LibraryError(PvStatus),LibraryLoadError,FrameLengthError,ArgumentError,}
Enum describing possible error types returned from the Leopard Rust SDK.
leopard::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 Leopard library.