Picovoice WordmarkPicovoice Console
Introduction
Introduction
AndroidC.NETFlutterlink to GoiOSJavaNvidia JetsonLinuxmacOSNodejsPythonRaspberry PiReact NativeRustWebWindows
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
SummaryPicovoice LeopardAmazon TranscribeAzure Speech-to-TextGoogle ASRGoogle ASR (Enhanced)IBM Watson Speech-to-Text
FAQ
Introduction
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
FAQ
Introduction
AndroidCiOSLinuxmacOSPythonWebWindows
AndroidCiOSPythonWeb
SummaryOctopus Speech-to-IndexGoogle Speech-to-TextMozilla DeepSpeech
FAQ
Introduction
AndroidAngularArduinoBeagleBoneCChrome.NETEdgeFirefoxFlutterlink to GoiOSJavaNvidia JetsonLinuxmacOSMicrocontrollerNodejsPythonRaspberry PiReactReact NativeRustSafariUnityVueWebWindows
AndroidAngularC.NETFlutterlink to GoiOSJavaMicrocontrollerNodejsPythonReactReact NativeRustUnityVueWeb
SummaryPorcupineSnowboyPocketSphinx
Wake Word TipsFAQ
Introduction
AndroidAngularBeagleBoneCChrome.NETEdgeFirefoxFlutterlink to GoiOSJavaNvidia JetsonlinuxmacOSNodejsPythonRaspberry PiReactReact NativeRustSafariUnityVueWebWindows
AndroidAngularC.NETFlutterlink to GoiOSJavaNodejsPythonReactReact NativeRustUnityVueWeb
SummaryPicovoice RhinoGoogle DialogflowAmazon LexIBM WatsonMicrosoft LUIS
Expression SyntaxFAQ
Introduction
AndroidBeagleboneCiOSNvidia JetsonLinuxmacOSPythonRaspberry PiRustWebWindows
AndroidCiOSPythonRustWeb
SummaryPicovoice CobraWebRTC VAD
FAQ
Introduction
AndroidAngularArduinoBeagleBoneC.NETFlutterlink to GoiOSJavaNvidia JetsonMicrocontrollerNodejsPythonRaspberry PiReactReact NativeRustUnityVueWeb
AndroidAngularCMicrocontroller.NETFlutterlink to GoiOSJavaNodejsPythonReactReact NativeRustUnityVueWeb
Picovoice SDK - FAQ
IntroductionSTM32F407G-DISC1 (Arm Cortex-M4)STM32F411E-DISCO (Arm Cortex-M4)STM32F769I-DISCO (Arm Cortex-M7)IMXRT1050-EVKB (Arm Cortex-M7)
FAQGlossary

Porcupine Wake Word — 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

  • String: Current Porcupine version.

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

  • PorcupineException: If there is an error while processing the audio frame.

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

  • accessKey String : AccessKey obtained from Picovoice Console.

Returns

  • Porcupine.Builder: The instance of Porcupine.Builder object.

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: The instance of Porcupine.Builder object.

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: The instance of Porcupine.Builder object.

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: The instance of Porcupine.Builder object.

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: The instance of Porcupine.Builder object.

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: The instance of Porcupine.Builder object.

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: The instance of Porcupine.Builder object.

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: The instance of Porcupine.Builder object.

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

  • Porcupine.Builder: The instance of Porcupine.Builder object.

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 { }

Was this doc helpful?

Issue with this doc?

Report a GitHub Issue
Porcupine Wake Word — Java API
  • Porcupine
  • Porcupine()
  • delete()
  • getFrameLength()
  • getSampleRate()
  • getVersion()
  • process()
  • BuiltInKeyword
  • Porcupine.Builder
  • build()
  • setAccessKey()
  • setBuiltInKeyword()
  • setBuiltInKeywords()
  • setKeywordPath()
  • setKeywordPaths()
  • setLibraryPath()
  • setModelPath()
  • setSensitivity()
  • setSensitivities()
  • PorcupineException
Platform
  • Leopard Speech-to-Text
  • Cheetah Streaming Speech-to-Text
  • Octopus Speech-to-Index
  • Porcupine Wake Word
  • Rhino Speech-to-Intent
  • Cobra Voice Activity Detection
Resources
  • Docs
  • Console
  • Blog
  • Demos
Sales
  • Pricing
  • Starter Tier
  • Enterprise
Company
  • Careers
Follow Picovoice
  • LinkedIn
  • GitHub
  • Twitter
  • Medium
  • YouTube
  • AngelList
Subscribe to our newsletter
Terms of Use
Privacy Policy
© 2019-2022 Picovoice Inc.