Porcupine Wake Word
Java API
API Reference for the Java Porcupine SDK (porcupine-java)
package: ai.picovoice.porcupine
Porcupine
Class for the Porcupine wake word engine.
Porcupine can be initialized using the Porcupine.Builder Class. Resources should be cleaned when you are done using the delete() function.
Porcupine.Porcupine()
Porcupine constructor. See also the Porcupine.Builder Class.
Parameters
accessKeyString : AccessKey obtained from Picovoice Console.libraryPathString : Absolute path to the native Porcupine library.modelPathString : Absolute path to the file containing model parameters.keywordPathsString[] : Absolute paths to keyword model files.sensitivitiesfloat[] : Sensitivities for detecting keywords. Each value should be a number within [0, 1].
Returns
Porcupine: An instance of Porcupine wake word engine.
Throws
PorcupineException: If an error occurs while creating an instance of Porcupine wake word engine.
Porcupine.delete()
Releases resources acquired by Porcupine.
Porcupine.getFrameLength()
Getter for number of audio samples per frame.
Returns
int: Number of audio samples per frame.
Porcupine.getSampleRate()
Getter for audio sample rate accepted by Picovoice.
Returns
int: Audio sample rate accepted by Picovoice.
Porcupine.getVersion()
Getter for version.
Returns
String: CurrentPorcupineversion.
Porcupine.process()
Processes a frame of the incoming audio stream and emits the detection result. The number of samples per frame can be attained by calling getFrameLength(). The incoming audio needs to have a sample rate equal to getSampleRate() and be 16-bit linearly-encoded. Porcupine operates on single-channel audio.
Parameters
pcmshort[] : A frame of audio samples.
Returns
int: Index of observed keyword at the end of the current frame. Indexing is 0-based and matches the ordering of keyword models provided to the constructor. If no keyword is detected then it returns -1.
Throws
PorcupineException: If there is an error while processing the audio frame.
Porcupine.BuiltInKeyword
Enum of available built-in keywords for Porcupine wake word engine.
Values:
ALEXAAMERICANOBLUEBERRYBUMBLEBEECOMPUTERGRAPEFRUITGRASSHOPPERHEY_GOOGLEHEY_SIRIJARVISOK_GOOGLEPICOVOICEPORCUPINETERMINATOR
Porcupine.Builder
Builder for creating an instance of Porcupine with a mixture of default arguments.
Porcupine.Builder.build()
Creates an instance of Porcupine wake word engine.
Returns
Porcupine: An instance of Porcupine wake word engine.
Throws
PorcupineException: If an error occurs while creating an instance of Porcupine wake word engine.
Porcupine.Builder.setAccessKey()
Sets the AccessKey to the builder.
Parameters
accessKeyString : AccessKey obtained from Picovoice Console.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setBuiltInKeyword()
Sets one keyword to the builder. This will replace the keywords set with setBuiltInKeywords().
build() will throw a PorcupineException if set together with setKeywordPath() or setKeywordPaths().
Parameters
keywordBuiltinKeyword : A keyword used for detection.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setBuiltInKeywords()
Sets keywords to the builder. This will replace the keyword set with setBuiltInKeyword().
build() will throw a PorcupineException if set together with setKeywordPath() or setKeywordPaths().
Parameters
keywordsBuiltInKeyword[] : List of keywords for detection.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setKeywordPath()
Sets one keywordPath to the builder. This will replace the keywordPaths set with setKeywordPaths().
build() will throw a PorcupineException if set together with setBuiltInKeyword() or setBuiltInKeywords().
Parameters
keywordPathString : Absolute path to one keyword file.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setKeywordPaths()
Sets keywordPaths to the builder. This will replace the keywordPath set with setKeywordPath().
build() will throw a PorcupineException if set together with setBuiltInKeyword() or setBuiltInKeywords().
Parameters
keywordPathsString[] : Absolute paths to keyword model files.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setLibraryPath()
Sets the native library path to the builder. If not set it will be set to the default location.
Parameters
libraryPathString : Absolute path to the native Porcupine library.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setModelPath()
Sets the model path to the builder. If not set it will be set to the default location.
Parameters
modelPathString : Absolute path to the file containing model parameters.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setSensitivity()
Sets sensitivity to the build. Value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate. This will replace the sensitivities set with setSensitivities().
This should be used if setBuiltInKeyword() or setKeywordPath() was used.
Parameters
sensitivityfloat: Sensitivity for detecting keyword.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
Porcupine.Builder.setSensitivities()
Sets sensitivities to the build. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
This should be the same size as the number of keywords or keywordPaths set by setBuiltInKeywords() setKeywordPaths(). If not set, each will be set to 0.5. This will replace the sensitivity set with setSensitivity().
Parameters
sensitivitiesfloat[] : Sensitivities for detecting keywords.
Returns
Porcupine.Builder: The instance of Porcupine.Builder object.
PorcupineException
Exception thrown if an error occurs within Porcupine wake word engine.
Exceptions: