Porcupine Wake Word
Android API
API Reference for the Android Porcupine SDK (porcupine-android)
package: ai.picovoice.porcupine
Porcupine
Class for the Porcupine Wake Word engine.
Porcupine must be initialized using the Builder() Class. Resources should be cleaned when you are done using the delete() function.
Porcupine.BuiltInKeyword
Enum of available built-in keywords for Porcupine Wake Word engine.
Values:
ALEXAAMERICANOBLUEBERRYBUMBLEBEECOMPUTERGRAPEFRUITGRASSHOPPERHEY_GOOGLEHEY_SIRIJARVISOK_GOOGLEPICOVOICEPORCUPINETERMINATOR
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.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.
Parameters
contextContext : The Android app context
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 of the builder.
Parameters
accessKeyString : AccessKey obtained from Picovoice Console.
Returns
Porcupine.Builder: Modified Porcupine.Builder object.
Porcupine.Builder.setKeyword()
Sets one keyword of the builder. This will replace the keywords set with setKeywords().
build() will throw a PorcupineException if set together with setKeywordPath() or setKeywordPaths().
Parameters
keywordBuiltinKeyword : A keyword used for detection.
Returns
Porcupine.Builder: Modified Porcupine.Builder object.
Porcupine.Builder.setKeywordPath()
Sets one keywordPath of the builder. This will replace the keywordPaths set with setKeywordPaths().
build() will throw a PorcupineException if set together with setKeyword() or setKeywords().
Parameters
keywordPathString : Path to a keyword file (.ppn). Can be either a path that is relative to the project'sassetsfolder or an absolute path to the file on device.
Returns
Porcupine.Builder: Modified Porcupine.Builder object.
Porcupine.Builder.setKeywordPaths()
Sets keywordPaths of the builder. This will replace the keywordPath set with setKeywordPath().
build() will throw a PorcupineException if set together with setKeyword() or setKeywords().
Parameters
keywordPathsString : Paths to keyword model files (.ppn). Can be either paths that are relative to the project'sassetsfolder or absolute paths to the files on device.
Returns
Porcupine.Builder: Modified Porcupine.Builder object.
Porcupine.Builder.setKeywords()
Sets keywords of the builder. This will replace the keyword set with setKeyword().
build() will throw a PorcupineException if set together with setKeywordPath() or setKeywordPaths().
Parameters
keywordsBuiltInKeyword[] : List of keywords for detection.
Returns
Porcupine.Builder: Modified Porcupine.Builder object.
Porcupine.Builder.setModelPath()
Sets the model path of the builder. If not set it will be set to the default location.
Parameters
modelPathString : Path to the file containing model parameters (.pv). Can be either a path that is relative to the project'sassetsfolder or an absolute path to the file on device.
Returns
Porcupine.Builder: Modified Porcupine.Builder object.
Porcupine.Builder.setSensitivities()
Sets sensitivities of the builder. 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 setKeywords() 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: Modified Porcupine.Builder object.
Porcupine.Builder.setSensitivity()
Sets sensitivity of the builder. 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 setKeyword() or setKeywordPath() was used.
Parameters
sensitivityfloat: Sensitivity for detecting keyword.
Returns
Porcupine.Builder: Modified Porcupine.Builder object.
PorcupineException
Exception thrown if an error occurs within Porcupine Wake Word engine.
Exceptions:
PorcupineManager
High-level Android binding for Porcupine Wake Word engine. It handles recording audio from microphone, processes it in real-time using Porcupine, and notifies the client when any of the given keywords are detected.
PorcupineManager.delete()
Releases resources acquired by PorcupineManager.
PorcupineManager.start()
Starts recording audio from the microphone and monitors it for the utterances of the given set of keywords.
PorcupineManager.stop()
Stops recording audio from the microphone.
Throws
PorcupineException: If there is an error while stopping microphone.
PorcupineManager.Builder
Builder for creating an instance of PorcupineManager with a mixture of default arguments.
PorcupineManager.Builder.build()
Creates an instance of PorcupineManager.
Parameters
contextContext : The Android app context.callbackPorcupineManagerCallback : A callback function that is invoked upon detection of the keywords. The callback must be an instance ofPorcupineManagerCallback.
Returns
PorcupineManager: An instance of PorcupineManager.
Throws
PorcupineException: If an error occurs while creating an instance of PorcupineManager.
PorcupineManager.Builder.setAccessKey()
Sets the AccessKey of the builder.
Parameters
accessKeyString : AccessKey obtained from Picovoice Console.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setKeyword()
Sets one keyword of the builder. This will replace the keywords set with setKeywords().
build() will throw a PorcupineException if set together with setKeywordPath() or setKeywordPaths().
Parameters
keywordBuiltInKeyword : A keyword used for detection.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setKeywordPath()
Sets one keywordPath of the builder. This will replace the keywordPaths set with setKeywordPaths().
build() will throw a PorcupineManagerException if set together with setKeyword() or setKeywords().
Parameters
keywordPathString : Path to a keyword file (.ppn). Can be either a path that is relative to the project'sassetsfolder or an absolute path to the file on device.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setKeywordPaths()
Sets keywordPaths of the builder. This will replace the keywordPath set with setKeywordPath().
build() will throw a PorcupineException if set together with setKeyword() or setKeywords().
Parameters
keywordPathsString : Paths to keyword model files (.ppn). Can be either paths that are relative to the project'sassetsfolder or absolute paths to the file on device.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setKeywords()
Sets keywords of the builder. This will replace the keyword set with setKeyword().
build() will throw a PorcupineException if set together with setKeywordPath() or setKeywordPaths().
Parameters
keywordsBuiltInKeyword[]: List of keywords for detection.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setModelPath()
Sets the model path of the builder. If not set it will be set to the default location.
Parameters
modelPathString : Path to the file containing model parameters (.pv). Can be either a path that is relative to the project'sassetsfolder or an absolute path to the file on device.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setSensitivities()
Sets sensitivities of the builder. 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 setKeywords() 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
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setSensitivity()
Sets sensitivity of the builder. 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 setKeyword() or setKeywordPath() was used.
Parameters
sensitivityfloat : Sensitivity for detecting keyword.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManager.Builder.setErrorCallback()
Sets errorCallback of the builder.
Parameters
errorCallbackPorcupineManagerErrorCallback : A function to run if errors occur while processing audio frames.
Returns
PorcupineManager.Builder: Modified PorcupineManager.Builder object.
PorcupineManagerCallback
Callback interface invoked when a keyword has been detected.
PorcupineManagerErrorCallback
Callback interface invoked when an error occurs while processing audio.