Leopard - Java API
API Reference for the Java Leopard SDK (leopard-java)
package: ai.picovoice.leopard
Leopard
public class Leopard { }
Class for the Leopard Speech-to-Text engine.
Leopard can be initialized using the Leopard.Builder() Class. Resources should be cleaned
when you are done using the delete()
function.
Leopard.Leopard()
public Leopard(String accessKey,String libraryPath,String modelPath) throws LeopardException
Leopard
constructor. See also the Leopard.Builder
Class.
Parameters
accessKey
String : AccessKey obtained from Picovoice Console.libraryPath
String : Absolute path to the native Leopard library.modelPath
String : Absolute path to the file containing model parameters.
Returns
Leopard
: An instance of Leopard engine.
Throws
LeopardException
: if there is an error while initializing Leopard.
Leopard.delete()
public void delete()
Releases resources acquired by Leopard
.
Leopard.getSampleRate()
public int getSampleRate()
Getter for required audio sample rate for PCM data.
Returns
int
: Required audio sample rate for PCM data.
Leopard.getVersion()
public String getVersion()
Getter for version.
Returns
String
: CurrentLeopard
version.
Leopard.process()
public String process(short[] pcm) throws LeopardException
Processes given audio data and returns its transcription. The incoming audio needs to have a sample rate equal
to .getSampleRate()
and be 16-bit linearly-encoded. Furthermore, Leopard
operates on single channel audio. If you wish to process data in a different sample rate or format consider
using .processFile()
.
Parameters
pcm
short[] : A frame of audio samples.
Returns
string
: Inferred transcription.
Throws
LeopardException
: if there is an error while processing the audio frame.
Leopard.processFile()
public String processFile(String path) throws LeopardException
Processes a given audio file and returns its transcription.
Parameters
path
String : Absolute path to the audio file. The file needs to have a sample rate equal to or greater thansampleRate[]
. The supported formats are:FLAC
,MP3
,Ogg
,Opus
,Vorbis
,WAV
, andWebM
.
Returns
string
: Inferred transcription.
Throws
LeopardException
: if there is an error while processing the audio file.
Leopard.Builder
public static class Builder {public Builder(String accessKey) { }}
Builder for creating an instance of Leopard
with a mixture of default arguments.
Parameters
accessKey
String : AccessKey obtained from Picovoice Console.
Leopard.Builder.build()
public Leopard build() throws LeopardException
Creates an instance of Leopard
Speech-to-Text engine.
Returns
Leopard
: An instance of Leopard Speech-to-Text engine.
Throws
LeopardException
: If an error occurs while creating an instance of Leopard Speech-to-Text engine.
Leopard.Builder.setAccessKey()
public Leopard.Builder setAccessKey(String accessKey)
Sets the AccessKey of the builder.
Parameters
accessKey
String : AccessKey obtained from Picovoice Console.
Returns
Leopard.Builder
: Modified Leopard.Builder object.
Leopard.Builder.setModelPath()
public Leopard.Builder setModelPath(String modelPath)
Sets the model path of the builder.
Parameters
modelPath
String : Absolute path to the file containing model parameters (.pv
).
Returns
Leopard.Builder
: Modified Leopard.Builder object.
Leopard.Builder.setLibraryPath()
public Builder setLibraryPath(String libraryPath)
Sets the library path of the builder.
Parameters
libraryPath
String : Absolute path to the native Leopard library.
Returns
Leopard.Builder
: Modified Leopard.Builder object.
LeopardException
public class LeopardException extends Exception { }
Exception thrown if an error occurs within Leopard
Speech-to-Text engine.
Exceptions:
public class LeopardActivationException extends LeopardException { }public class LeopardActivationLimitException extends LeopardException { }public class LeopardActivationRefusedException extends LeopardException { }public class LeopardActivationThrottledException extends LeopardException { }public class LeopardIOException extends LeopardException { }public class LeopardInvalidArgumentException extends LeopardException { }public class LeopardInvalidStateException extends LeopardException { }public class LeopardKeyException extends LeopardException { }public class LeopardMemoryException extends LeopardException { }public class LeopardRuntimeException extends LeopardException { }public class LeopardStopIterationException extends LeopardException { }