Leopard Speech-to-Text
C API
API Reference for the Leopard C SDK.
pv_leopard_t
Container representing the Leopard Speech-to-Text engine.
pv_leopard_init()
Creates a Leopard instance. Resources should be cleaned when you are done using the pv_leopard_delete() function.
Parameters
access_key
const char * : AccessKey obtained from Picovoice Console.model_path
const char * : Absolute path to the file containing model parameters (.pv
).enable_automatic_punctuation
bool : Set totrue
to enable automatic punctuation insertion.enable_diarization
bool: Set totrue
to enable speaker diarization, which allows Leopard to differentiate speakers as part of the transcription process. Word metadata will include aspeaker_tag
to identify unique speakers.object
pv_leopard_t * * : Constructed instance of Leopard.
Returns
- pv_status_t : Status code.
pv_leopard_delete()
Releases resources acquired by Leopard.
Parameters
object
pv_leopard_t * : Picovoice object.
pv_leopard_process()
Processes a given audio data and returns its transcription. The caller is responsible for freeing the transcript
and words
buffers using pv_leopard_transcript_delete()
and pv_leopard_words_delete(), respectively. The audio needs to have a sample rate equal
to pv_sample_rate()
and be 16-bit linearly-encoded. This function operates on single-channel audio.
Parameters
object
pv_leopard_t * : Leopard object.pcm
int16_t : A frame of audio samples.num_samples
int32_t : Number of audio samples to process.transcript
char * * : Inferred transcription.num_words
int32_t * : Number of transcribed words.words
pv_word_t * * : Transcribed words and their associated metadata.
Returns
- pv_status_t : Status code.
pv_leopard_process_file()
Processes a given audio file and returns its transcription. The caller is responsible for freeing the transcript
and words
buffers using pv_leopard_transcript_delete()
and pv_leopard_words_delete(), respectively. The supported formats
are: 3gp (AMR)
, FLAC
, MP3
, MP4/m4a (AAC)
, Ogg
, WAV
and WebM
.
Parameters
object
pv_leopard_t * : Leopard object.audio_path
const char * : Absolute path to the audio file.transcript
char * * : Inferred transcription.num_words
int32_t * : Number of transcribed words.words
pv_word_t * * : Transcribed words and their associated metadata.
Returns
- pv_status_t : Status code.
pv_leopard_transcript_delete()
Deletes transcript returned from pv_leopard_process() or pv_leopard_process_file().
Parameters
transcript
char * : transcription string returned from pv_leopard_process() or pv_leopard_process_file().
pv_leopard_words_delete()
Deletes words returned from pv_leopard_process() or pv_leopard_process_file().
Parameters
words
pv_word_t * * : transcribed words returned from pv_leopard_process() or pv_leopard_process_file().
pv_leopard_version()
Getter for version.
Returns
- const char * : Leopard version.
pv_sample_rate()
Audio sample rate accepted by Leopard.
Returns
- int32_t : Sample rate.
pv_word_t
Struct for a transcribed word and its associated metadata.
pv_status_t
Status code enum.
pv_status_to_string()
Parameters
status
int32_t : Status code.
Returns
- const char * : String representation of status code.
pv_get_error_stack()
If a function returns a failure (any pv_status_t other than PV_STATUS_SUCCESS
), this function can be
called to get a series of error messages related to the failure. This function can only be called only once per
failure status on another function. The memory for message_stack
must be freed using pv_free_error_stack
.
Regardless of the return status of this function, if message_stack
is not NULL
, then message_stack
contains valid memory. However, a failure status on this function indicates that future error messages
may not be reported.
Parameters
message_stack
const char * * * : Array of messages relating to the failure. Messages are NULL terminated strings. The array and messages must be freed usingpv_free_error_stack()
.message_stack_depth
int32_t * : The number of messages in themessage_stack
array.
Returns
- pv_status_t : Returned status code.
pv_free_error_stack()
This function frees the memory used by error messages allocated by pv_get_error_stack()
.
Parameters
message_stack
const char * * * : Array of messages relating to the failure.