javaPorcupine - Java API

API Reference for the Java Porcupine SDK (porcupine-java)

package: ai.picovoice.porcupine


Porcupine

public class 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()

public Porcupine(
String accessKey,
String libraryPath,
String modelPath,
String[] keywordPaths,
float[] sensitivities) throws PorcupineException

Porcupine constructor. See also the Porcupine.Builder Class.

Parameters

  • accessKey String : AccessKey obtained from Picovoice Console.
  • libraryPath String : Absolute path to the native Porcupine library.
  • modelPath String : Absolute path to the file containing model parameters.
  • keywordPaths String[] : Absolute paths to keyword model files.
  • sensitivities float[] : 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()

public void delete()

Releases resources acquired by Porcupine.


Porcupine.getFrameLength()

public int getFrameLength()

Getter for number of audio samples per frame.

Returns

  • int: Number of audio samples per frame.

Porcupine.getSampleRate()

public int getSampleRate()

Getter for audio sample rate accepted by Picovoice.

Returns

  • int: Audio sample rate accepted by Picovoice.

Porcupine.getVersion()

public String getVersion()

Getter for version.

Returns


Porcupine.process()

public int process(short[] pcm) throws PorcupineException

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

  • pcm short[] : 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


Porcupine.BuiltInKeyword

public enum BuiltInKeyword { }

Enum of available built-in keywords for Porcupine wake word engine.

Values:

  • ALEXA
  • AMERICANO
  • BLUEBERRY
  • BUMBLEBEE
  • COMPUTER
  • GRAPEFRUIT
  • GRASSHOPPER
  • HEY_GOOGLE
  • HEY_SIRI
  • JARVIS
  • OK_GOOGLE
  • PICOVOICE
  • PORCUPINE
  • TERMINATOR

Porcupine.Builder

public static class Builder { }

Builder for creating an instance of Porcupine with a mixture of default arguments.


Porcupine.Builder.build()

public Porcupine build() throws PorcupineException

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()

public Porcupine.Builder setAccessKey(String accessKey)

Sets the AccessKey to the builder.

Parameters

Returns


Porcupine.Builder.setBuiltInKeyword()

public Porcupine.Builder setBuiltInKeyword(BuiltInKeyword keyword)

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

  • keyword BuiltinKeyword : A keyword used for detection.

Returns


Porcupine.Builder.setBuiltInKeywords()

public Porcupine.Builder setBuiltInKeywords(BuiltInKeyword[] keywords)

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

  • keywords BuiltInKeyword[] : List of keywords for detection.

Returns


Porcupine.Builder.setKeywordPath()

public Porcupine.Builder setKeywordPath(String keywordPath)

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

  • keywordPath String : Absolute path to one keyword file.

Returns


Porcupine.Builder.setKeywordPaths()

public Porcupine.Builder setKeywordPaths(String[] keywordPaths)

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

  • keywordPaths String[] : Absolute paths to keyword model files.

Returns


Porcupine.Builder.setLibraryPath()

public Porcupine.Builder setLibraryPath(String libraryPath)

Sets the native library path to the builder. If not set it will be set to the default location.

Parameters

  • libraryPath String : Absolute path to the native Porcupine library.

Returns


Porcupine.Builder.setModelPath()

public Porcupine.Builder setModelPath(String modelPath)

Sets the model path to the builder. If not set it will be set to the default location.

Parameters

  • modelPath String : Absolute path to the file containing model parameters.

Returns


Porcupine.Builder.setSensitivity()

public Porcupine.Builder setSensitivity(float sensitivity)

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

  • sensitivity float: Sensitivity for detecting keyword.

Returns


Porcupine.Builder.setSensitivities()

public Porcupine.Builder setSensitivities(float[] sensitivities)

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

  • sensitivities float[] : Sensitivities for detecting keywords.

Returns


PorcupineException

public class PorcupineException extends Exception { }

Exception thrown if an error occurs within Porcupine wake word engine.

Exceptions:

public class PorcupineActivationException extends PorcupineException { }
public class PorcupineActivationLimitException extends PorcupineException { }
public class PorcupineActivationRefusedException extends PorcupineException { }
public class PorcupineActivationThrottledException extends PorcupineException { }
public class PorcupineIOException extends PorcupineException { }
public class PorcupineInvalidArgumentException extends PorcupineException { }
public class PorcupineInvalidStateException extends PorcupineException { }
public class PorcupineKeyException extends PorcupineException { }
public class PorcupineMemoryException extends PorcupineException { }
public class PorcupineRuntimeException extends PorcupineException { }
public class PorcupineStopIterationException extends PorcupineException { }

Issue with this doc? Please let us know.