Leopard Speech-to-Text
Rust API
API Reference for the Leopard Rust SDK (crates.io).
leopard::Leopard
Struct for the Leopard Speech-to-Text engine.
leopard::Leopard.process()
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>
: IfOk
, returns the inferred transcription as aLeopardTranscript
object. IfErr
, aLeopardError
object describing the error that was encountered.
leopard::Leopard.process_file()
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>
: IfOk
, returns the inferred transcription as aLeopardTranscript
object. IfErr
, aLeopardError
object describing the error that was encountered.
leopard::Leopard.sample_rate()
Gets the sample rate.
Returns
u32
: Audio sample rate accepted by Leopard.
leopard::Leopard.version()
Gets the Leopard version.
Returns
&str
: Leopard version string.
leopard::LeopardBuilder
Builder struct for creating an instance of Leopard
.
leopard::LeopardBuilder.new()
Creates a new LeopardBuilder
.
Returns
LeopardBuilder
: A new Builder object.
leopard::LeopardBuilder.access_key()
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()
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()
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()
Modifies the enable_automatic_punctuation
of a LeopardBuilder
object.
Parameters
enable_automatic_punctuation
bool : Set totrue
to enable automatic punctuation insertion.
Returns
LeopardBuilder
: The modified Builder object.
leopard::LeopardBuilder.enable_diarization()
Modifies the enable_diarization
of a LeopardBuilder
object.
Parameters
enable_automatic_punctuation
bool : Set totrue
to enable speaker diarization, which allows Leopard to differentiate speakers as part of the transcription process. Word metadata will include aspeakerTag
to identify unique speakers.
Returns
LeopardBuilder
: The modified Builder object.
leopard::LeopardBuilder.init()
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::LeopardWord
Struct containing a transcribed word and associated word metadata.
word
String : Transcribed word.start_sec
f32 : Start of word in seconds.end_sec
f32 : End of word in seconds.confidence
f32 : Transcription confidence. It is a number within [0, 1].speaker_tag
i32 : The speaker tag is-1
if diarization is not enabled during initialization; otherwise, it's a non-negative integer identifying unique speakers, with0
reserved for unknown speakers.
leopard::LeopardTranscript
Struct containing a transcript and transcribed words from Leopard.
leopard::LeopardError
An error type describing any errors encountered by the Leopard SDK.
leopard::LeopardError.new()
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
Enum describing possible error types returned from the Leopard Rust SDK.
leopard::PvStatus
Error codes returned from the Leopard library.