Class Picovoice

java.lang.Object
ai.picovoice.picovoice.Picovoice

public class Picovoice extends Object
Java binding for Picovoice end-to-end platform. Picovoice enables building voice experiences similar to Alexa but runs entirely on-device (offline).

Picovoice detects utterances of a customizable wake word (phrase) within an incoming stream of audio in real-time. After detection of wake word, it begins to infer the user's intent from the follow-on spoken command. Upon detection of wake word and completion of voice command, it invokes user-provided callbacks to signal these events.

Picovoice processes incoming audio in consecutive frames. The number of samples per frame is $getFrameLength(). The incoming audio needs to have a sample rate equal to $getSampleRate() and be 16-bit linearly-encoded. Picovoice operates on single-channel audio. It uses Porcupine wake word engine for wake word detection and Rhino Speech-to-Intent engine for intent inference.

  • Constructor Details

    • Picovoice

      public Picovoice(String accessKey, String porcupineLibraryPath, String porcupineModelPath, String keywordPath, float porcupineSensitivity, PicovoiceWakeWordCallback wakeWordCallback, String rhinoLibraryPath, String rhinoModelPath, String contextPath, float rhinoSensitivity, float endpointDurationSec, boolean requireEndpoint, PicovoiceInferenceCallback inferenceCallback) throws PicovoiceException
      Constructor.
      Parameters:
      accessKey - AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
      porcupineModelPath - Absolute path to the file containing Porcupine's model parameters.
      keywordPath - Absolute path to Porcupine's keyword model file.
      porcupineSensitivity - Wake word detection sensitivity. It should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
      wakeWordCallback - User-defined callback invoked upon detection of the wake phrase. $PicovoiceWakeWordCallback defines the interface of the callback.
      rhinoModelPath - Absolute path to the file containing Rhino's model parameters.
      contextPath - Absolute path to file containing context parameters. A context represents the set of expressions (spoken commands), intents, and intent arguments (slots) within a domain of interest.
      rhinoSensitivity - Inference sensitivity. It should be a number within [0, 1]. A higher sensitivity value results in fewer misses at the cost of (potentially) increasing the erroneous inference rate.
      endpointDurationSec - Endpoint duration in seconds. An endpoint is a chunk of silence at the end of an utterance that marks the end of spoken command. It should be a positive number within [0.5, 5]. A lower endpoint duration reduces delay and improves responsiveness. A higher endpoint duration assures Rhino doesn't return inference pre-emptively in case the user pauses before finishing the request.
      requireEndpoint - If set to `true`, Rhino requires an endpoint (a chunk of silence) after the spoken command. If set to `false`, Rhino tries to detect silence, but if it cannot, it still will provide inference regardless. Set to `false` only if operating in an environment with overlapping speech (e.g. people talking in the background).
      inferenceCallback - User-defined callback invoked upon completion of intent inference. #PicovoiceInferenceCallback defines the interface of the callback.
      Throws:
      PicovoiceException - if there is an error while initializing.
  • Method Details

    • delete

      public void delete()
      Releases resources acquired.
    • 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 - A frame of audio samples. 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. Picovoice operates on single-channel audio.
      Throws:
      PicovoiceException - if there is an error while processing the audio frame.
    • getVersion

      public String getVersion()
      Getter for version.
      Returns:
      Version.
    • getPorcupineVersion

      public String getPorcupineVersion()
      Getter for Porcupine version.
      Returns:
      Porcupine version.
    • getRhinoVersion

      public String getRhinoVersion()
      Getter for Rhino version.
      Returns:
      Rhino version.
    • getFrameLength

      public int getFrameLength()
      Getter for number of audio samples per frame.
      Returns:
      Number of audio samples per frame.
    • getSampleRate

      public int getSampleRate()
      Getter for audio sample rate accepted by Picovoice.
      Returns:
      Audio sample rate accepted by Picovoice.
    • getContextInformation

      public String getContextInformation() throws PicovoiceException
      Getter for the Rhino context.
      Returns:
      Rhino context
      Throws:
      PicovoiceException