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
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

Leopard Speech-to-Text — 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<LeopardTranscript, 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<LeopardTranscript, LeopardError> : If Ok, returns the inferred transcription as a LeopardTranscript object. If Err, a LeopardError object describing the error that was encountered.

leopard::Leopard.process_file()

pub fn process_file<P: AsRef<Path>>(&self, audio_path: P) -> Result<LeopardTranscript, LeopardError>

Processes a given audio file and returns its transcription. The supported audio file formats are: 3gp (AMR), FLAC, MP3, MP4/m4a (AAC), Ogg, WAV and WebM.

Parameters

  • audio_path P : Absolute path to the audio file.

Returns

  • Result<LeopardTranscript, LeopardError> : If Ok, returns the inferred transcription as a LeopardTranscript object. If Err, a LeopardError 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()) -> Self

Creates a new LeopardBuilder.

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.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.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.enable_automatic_punctuation()

pub fn enable_automatic_punctuation(&mut self, enable_automatic_punctuation: bool) -> &mut Self

Modifies the enable_automatic_punctuation of a LeopardBuilder object.

Parameters

  • enable_automatic_punctuation bool : Set to true to enable automatic punctuation insertion.

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> : If Ok, an initialized instance of Leopard. If Err, an instance of LeopardError detailing the error that was encountered.

leopard::LeopardWord

#[derive(PartialEq, Clone, Debug)]
pub struct LeopardWord {
pub word: String,
pub start_sec: f32,
pub end_sec: f32,
pub confidence: f32,
}

Struct containing a transcribed word and associated word metadata.


leopard::LeopardTranscript

#[derive(PartialEq, Clone, Debug)]
pub struct LeopardTranscript {
pub transcript: String,
pub words: Vec<LeopardWord>,
}

Struct containing a transcript and transcribed words from Leopard.


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.

Was this doc helpful?

Issue with this doc?

Report a GitHub Issue
Leopard Speech-to-Text — Rust API
  • leopard::Leopard
  • process()
  • process_file()
  • sample_rate()
  • version()
  • leopard::LeopardBuilder
  • new()
  • access_key()
  • model_path()
  • library_path()
  • enable_automatic_punctuation()
  • init()
  • leopard::LeopardWord
  • leopard::LeopardTranscript
  • leopard::LeopardError
  • new()
  • leopard::LeopardErrorStatus
  • leopard::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.