Octopus - Android API
API Reference for the Android Octopus SDK (octopus-android)
package: ai.picovoice.octopus
Octopus
public class Octopus { }
Class for the Octopus Speech-to-Index engine.
Octopus must be initialized using the Builder() Class. Resources should be cleaned when you are done using the delete()
function.
Octopus.delete()
public void delete()
Releases resources acquired by Octopus
.
Octopus.getPcmDataSampleRate()
public int getPcmDataSampleRate()
Getter for required audio sample rate for PCM data.
Returns
int
: Required audio sample rate for PCM data.
Octopus.getVersion()
public String getVersion()
Getter for version.
Returns
String
: CurrentOctopus
version.
Octopus.indexAudioData()
public OctopusMetadata indexAudioData(short[] pcm) throws OctopusException
Indexes given PCM audio data. The incoming audio needs to have a sample rate equal to .getSampleRate()
and be 16-bit linearly-encoded. Furthermore, Octopus
operates on single channel audio. If you wish to process data in a different sample rate or format consider using .processFile()
.
Parameters
pcm
short[] : An array of audio samples.
Returns
OctopusMetadata
: Octopus metadata object.
Throws
OctopusException
: if there is an error while processing the audio data.
Octopus.indexAudioFile()
public OctopusMetadata indexAudioFile(String path) throws OctopusException
Indexes an audio file.
Parameters
path
String : Absolute path to an audio file.
Returns
OctopusMetadata
: Octopus metadata object.
Throws
OctopusException
: if there is an error while processing the audio file.
Octopus.search()
public HashMap<String, OctopusMatch[]> search(OctopusMetadata metadata,HashSet<String> phrases) throws OctopusException
Searches metadata for a given set of phrases.
Parameters
metadata
OctopusMetadata : Absolute path to an audio file.
Returns
HashMap<String, OctopusMatch[]>
: A map of phrases and match arrays. Matches are represented by immutable OctopusMatch objects.
Throws
OctopusException
: if there is an error while searching the metadata.
Octopus.Builder
public static class Builder { }
Builder for creating an instance of Octopus
with a mixture of default arguments.
Octopus.Builder.build()
public Octopus build(Context context) throws OctopusException
Creates an instance of Octopus
Speech-to-Index engine.
Parameters
context
Context : The Android app context.
Returns
Octopus
: An instance of Octopus Speech-to-Index engine.
Throws
OctopusException
: If an error occurs while creating an instance of Octopus Speech-to-Index engine.
Octopus.Builder.setAccessKey()
public Octopus.Builder setAccessKey(String accessKey)
Sets the AccessKey of the builder.
Parameters
accessKey
String : AccessKey provided by Picovoice Console.
Returns
Octopus.Builder
: Modified Octopus.Builder object.
Octopus.Builder.setModelPath()
public Octopus.Builder setModelPath(String modelPath)
Sets the model path of the builder.
Parameters
modelPath
String : Absolute path to the file containing model parameters (.pv
).
Returns
Octopus.Builder
: Modified Octopus.Builder object.
OctopusMetadata
public class OctopusMetadata {public OctopusMetadata(byte[] metadataBytes) { }}
Type which contains audio metadata to be searched against. The object can be serialized (via .getBytes()
) and deserialized (via constructor)) for reuse. Resources must explicitly be released by calling .delete()
.
Parameters
metadataBytes
byte[] : A byte array previously obtained via.getBytes()
.
OctopusMetadata.getBytes()
public byte[] getBytes()
Gets the metadata in the form of a byte array.
Returns
byte[]
: The metadata in the form of a byte array.
OctopusMetadata.delete()
public void delete()
Releases resources acquired by OctopusMetadata.
OctopusMatch
public class OctopusMatch
Type which contains a search result from a call to .search()
.
OctopusMatch.getStartSec()
public float getStartSec()
Getter for the start of a match.
Returns
float
: Start of the matched audio in seconds.
OctopusMatch.getEndSec()
public float getEndSec()
Getter for the end of a match.
Returns
float
: End of the matched audio in seconds.
OctopusMatch.getProbability()
public float getProbability()
Getter for the probability (confidence) that this matches the search phrase.
Returns
float
: Probability (confidence) of match in range [0, 1].
OctopusException
public class OctopusException extends Exception { }
Exception thrown if an error occurs within Octopus
Speech-to-Index engine.
Exceptions:
public class OctopusActivationException extends OctopusException { }public class OctopusActivationLimitException extends OctopusException { }public class OctopusActivationRefusedException extends OctopusException { }public class OctopusActivationThrottledException extends OctopusException { }public class OctopusIOException extends OctopusException { }public class OctopusInvalidArgumentException extends OctopusException { }public class OctopusInvalidStateException extends OctopusException { }public class OctopusKeyException extends OctopusException { }public class OctopusMemoryException extends OctopusException { }public class OctopusRuntimeException extends OctopusException { }public class OctopusStopIterationException extends OctopusException { }