javaPicovoice Platform — Java API

API Reference for the Java Picovoice SDK (picovoice-java)

package: ai.picovoice.picovoice


Picovoice

public class Picovoice { }

Class for the Picovoice engine.

Picovoice can be initialized using the Picovoice.Builder Class. Resources should be cleaned when you are done using the delete() function.


Picovoice.Picovoice()

public Picovoice(
String accessKey,
String porcupineLibraryPath,
String porcupineModelPath,
String keywordPath,
float porcupineSensitivity,
PicovoiceWakeWordCallback wakeWordCallback,
String rhinoLibraryPath,
String rhinoModelPath,
String contextPath,
float rhinoSensitivity,
boolean requireEndpoint,
PicovoiceInferenceCallback inferenceCallback) throws PicovoiceException

Picovoice constructor. See also the Picovoice.Builder Class.

Parameters

  • accessKey String : AccessKey obtained from Picovoice Console.
  • porcupineModelPath String : Absolute path to the file containing Porcupine's model parameters.
  • keywordPath String : Absolute path to Porcupine's keyword model file.
  • porcupineSensitivity String : Wake word detection sensitivity. It should be a number within [0, 1].
  • wakeWordCallback String : User-defined callback invoked upon detection of the wake phrase. PicovoiceWakeWordCallback defines the interface of the callback.
  • rhinoModelPath String : Absolute path to the file containing Rhino's model parameters.
  • contextPath String : Absolute path to file containing Rhino context parameters.
  • rhinoSensitivity String : Inference sensitivity. It should be a number within [0, 1].
  • requireEndpoint String : If set to false, Rhino does not require an endpoint (chunk of silence) before finishing inference.
  • inferenceCallback String : User-defined callback invoked upon completion of intent inference. PicovoiceInferenceCallback defines the interface of the callback.

Returns

  • Picovoice: An instance of the Picovoice engine.

Throws

  • PicovoiceException: If an error occurs while creating an instance of the Picovoice engine.

Picovoice.delete()

public void delete()

Releases resources acquired by Picovoice.


Picovoice.getFrameLength()

public int getFrameLength()

Getter for number of audio samples per frame.

Returns

  • int: Number of audio samples per frame.

Picovoice.getSampleRate()

public int getSampleRate()

Getter for audio sample rate accepted by Picovoice.

Returns

  • int: Audio sample rate accepted by Picovoice.

Picovoice.getVersion()

public String getVersion()

Getter for version.

Returns


Picovoice.getContextInformation()

public String getContextInformation()

Getter for context information.

Returns

  • String: Returns the context information.

Picovoice.process()

public void process(short[] pcm) throws PicovoiceException

Processes a frame of the incoming audio stream. Upon detection of wake word and completion of follow-on command inference invokes user-defined callbacks.

Parameters

  • pcm short[] : A frame of audio samples.

Throws


Picovoice.Builder

public static class Builder { }

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


Picovoice.Builder.build()

public Picovoice build() throws RhinoException

Creates an instance of the Picovoice engine.

Returns

  • Picovoice: An instance of the Picovoice engine.

Throws

  • PicovoiceException: If an error occurs while creating an instance of the Picovoice engine.

Picovoice.Builder.setAccessKey()

public Picovoice.Builder setAccessKey(String accessKey)

Sets the AccessKey to the builder.

Parameters

Returns


Picovoice.Builder.setPorcupineLibraryPath()

public Picovoice.Builder setPorcupineLibraryPath(String porcupineLibraryPath)

Sets the Porcupine library path to the builder.

Parameters

  • porcupineLibraryPath String : Absolute path to the file containing the Porcupine native library.

Returns


Picovoice.Builder.setPorcupineModelPath()

public Picovoice.Builder setPorcupineModelPath(String porcupineModelPath)

Sets the Porcupine model path to the builder.

Parameters

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

Returns


Picovoice.Builder.setKeywordPath()

public Picovoice.Builder setKeywordPath(String keywordPath)

Sets the Porcupine keyword path to the builder.

Parameters

  • keywordPath String : Absolute path to the file containing the Porcupine keyword model.

Returns


Picovoice.Builder.setPorcupineSensitivity()

public Picovoice.Builder setPorcupineSensitivity(float porcupineSensitivity)

Sets Porcupine's keyword sensitivity to 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.

Parameters

  • porcupineSensitivity float : Sensitivity for detecting keyword.

Returns


Picovoice.Builder.setWakeWordCallback()

public Picovoice.Builder setWakeWordCallback(PicovoiceWakeWordCallback wakeWordCallback)

Sets the wake word callback object to the builder.

Parameters

Returns


Picovoice.Builder.setRhinoLibraryPath()

public Picovoice.Builder setRhinoLibraryPath(String rhinoLibraryPath)

Sets the Rhino library path to the builder.

Parameters

  • rhinoLibraryPath String : Absolute path to the file containing the Rhino native library.

Returns


Picovoice.Builder.setRhinoModelPath()

public Picovoice.Builder setRhinoModelPath(String rhinoModelPath)

Sets the Rhino model path to the builder.

Parameters

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

Returns


Picovoice.Builder.setContextPath()

public Picovoice.Builder setContextPath(String contextPath)

Sets the Rhino context path to the builder.

Parameters

  • contextPath String : Absolute path to the file containing the Rhino context model.

Returns


Picovoice.Builder.setRhinoSensitivity()

public Picovoice.Builder setRhinoSensitivity(float rhinoSensitivity)

Sets Rhino's sensitivity to 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.

Parameters

  • rhinoSensitivity float : Sensitivity for inferring intent.

Returns


Picovoice.Builder.setInferenceCallback()

public Picovoice.Builder setInferenceCallback(PicovoiceInferenceCallback inferenceCallback)

Sets the inference callback object to the builder.

Parameters

Returns


Picovoice.Builder.setRequireEndpoint()

public Picovoice.Builder setRequireEndpoint(boolean requireEndpoint)

Sets requireEndpoint to the builder. If set to false, Rhino does not require an endpoint (chunk of silence) before finishing inference.

Parameters

  • requireEndpoint boolean: Indicates whether an endpoint is required for Rhino to finish inference.

Returns


PicovoiceWakeWordCallback

public interface PicovoiceWakeWordCallback {
void invoke();
}

Callback interface invoked when a keyword has been detected.


PicovoiceInferenceCallback

public interface PicovoiceInferenceCallback {
void invoke(RhinoInference inference);
}

Callback interface invoked when a inference has been finalized.

Parameters


PicovoiceException

public class PicovoiceException extends Exception { }

Exception thrown if an error occurs within the Picovoice engine.

Exceptions:

public class PicovoiceActivationException extends PicovoiceException { }
public class PicovoiceActivationLimitException extends PicovoiceException { }
public class PicovoiceActivationRefusedException extends PicovoiceException { }
public class PicovoiceActivationThrottledException extends PicovoiceException { }
public class PicovoiceIOException extends PicovoiceException { }
public class PicovoiceInvalidArgumentException extends PicovoiceException { }
public class PicovoiceInvalidStateException extends PicovoiceException { }
public class PicovoiceKeyException extends PicovoiceException { }
public class PicovoiceMemoryException extends PicovoiceException { }
public class PicovoiceRuntimeException extends PicovoiceException { }
public class PicovoiceStopIterationException extends PicovoiceException { }

Issue with this doc? Please let us know.