Class Picovoice


  • public class Picovoice
    extends java.lang.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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Picovoice.Builder
      Builder for creating an instance of Picovoice with a mixture of default arguments
    • Constructor Summary

      Constructors 
      Constructor Description
      Picovoice​(java.lang.String accessKey, java.lang.String porcupineLibraryPath, java.lang.String porcupineModelPath, java.lang.String keywordPath, float porcupineSensitivity, PicovoiceWakeWordCallback wakeWordCallback, java.lang.String rhinoLibraryPath, java.lang.String rhinoModelPath, java.lang.String contextPath, float rhinoSensitivity, boolean requireEndpoint, PicovoiceInferenceCallback inferenceCallback)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete()
      Releases resources acquired.
      java.lang.String getContextInformation()
      Getter for the Rhino context
      int getFrameLength()
      Getter for number of audio samples per frame..
      java.lang.String getPorcupineVersion()
      Getter for Porcupine version.
      java.lang.String getRhinoVersion()
      Getter for Rhino version.
      int getSampleRate()
      Getter for audio sample rate accepted by Picovoice.
      java.lang.String getVersion()
      Getter for version.
      void process​(short[] pcm)
      Processes a frame of the incoming audio stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Picovoice

        public Picovoice​(java.lang.String accessKey,
                         java.lang.String porcupineLibraryPath,
                         java.lang.String porcupineModelPath,
                         java.lang.String keywordPath,
                         float porcupineSensitivity,
                         PicovoiceWakeWordCallback wakeWordCallback,
                         java.lang.String rhinoLibraryPath,
                         java.lang.String rhinoModelPath,
                         java.lang.String contextPath,
                         float rhinoSensitivity,
                         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.
        requireEndpoint - If set to `False`, Rhino does not require an endpoint (chunk of silence) before finishing inference.
        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 Detail

      • 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 java.lang.String getVersion()
        Getter for version.
        Returns:
        Version.
      • getPorcupineVersion

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

        public java.lang.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 java.lang.String getContextInformation()
        Getter for the Rhino context
        Returns:
        Rhino context