Leopard Speech-to-Text
React API
API Reference for the Leopard React SDK (npmjs).
useLeopard()
React Hook for Leopard
speech-to-text engine.
Returns
result
LeopardTranscript | null : A state containing the transcript result value.isLoaded
boolean : A state indicating whether the engine has initialized successfully.error
Error | null : AnError
object containing details about the error.init
(...) => Promise<void> : A method to initializeLeopard
given the arguments. Seeinit
.processFile
(...) => Promise<void> : A method to process audio files. SeeprocessFile
.startRecording
(...) => Promise<void> : A method to start recording audio. SeestartRecording
.stopRecording
() => Promise<void> : A method to stop recording audio and begin processing. SeestopRecording
.isRecording
boolean : A state indicating whetherwebVoiceProcessor
is passing audio to the engine.recordingElapsedSec
number : The amount of time (in seconds) elapsed while recording.release
() => Promise<void> : Releases resources acquired byuseLeopard
. Seerelease
.
init()
Initializes useLeopard
hook. Sets isLoaded
to true
.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.model
LeopardModel : Object containing Leopard model.options
LeopardOptions : Optional configuration arguments.
processFile()
Processes an audio file, which should be provided as a File
object with a MIME type of audio
and encoded in linear PCM format.
Parameters
file
File : File object with the MIME type = audio.
startRecording()
Start recording audio. If started, isRecording
is set to true
.
Parameters
maxRecordingSec
number : Optional configuration argument to set the maximum time in seconds Leopard is able to record. If unspecified, a default value of 120 will be used. This is to prevent unbounded memory usage.
stopRecording()
Stop recording audio and begin processing the buffered audio. Sets isRecording
to false
.
release()
Releases resources acquired by the useLeopard
. Sets isLoaded
and isRecording
to false, recordingElapsedSec
to 0, and error
to null.