Class Porcupine


  • public class Porcupine
    extends java.lang.Object
    Java binding for Porcupine wake word engine. It detects utterances of given keywords within an incoming stream of audio in real-time. It processes incoming audio in consecutive frames and for each frame 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.
    • Nested Class Summary

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

      Constructors 
      Constructor Description
      Porcupine​(java.lang.String accessKey, java.lang.String libraryPath, java.lang.String modelPath, java.lang.String[] keywordPaths, float[] sensitivities)
      Constructor.
    • Method Summary

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

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

      • LIBRARY_PATH

        public static final java.lang.String LIBRARY_PATH
      • MODEL_PATH

        public static final java.lang.String MODEL_PATH
      • BUILT_IN_KEYWORD_PATHS

        public static final java.util.HashMap<Porcupine.BuiltInKeyword,​java.lang.String> BUILT_IN_KEYWORD_PATHS
    • Constructor Detail

      • Porcupine

        public Porcupine​(java.lang.String accessKey,
                         java.lang.String libraryPath,
                         java.lang.String modelPath,
                         java.lang.String[] keywordPaths,
                         float[] sensitivities)
                  throws PorcupineException
        Constructor.
        Parameters:
        accessKey - AccessKey obtained from Picovoice Console.
        libraryPath - Absolute path to the native Porcupine library.
        modelPath - Absolute path to the file containing model parameters.
        keywordPaths - Absolute paths to keyword model files.
        sensitivities - Sensitivities for detecting keywords. 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.
        Throws:
        PorcupineException - if there is an error while initializing Porcupine.
    • Method Detail

      • setSdk

        public static void setSdk​(java.lang.String sdk)
      • delete

        public void delete()
        Releases resources acquired by Porcupine.
      • process

        public int process​(short[] pcm)
                    throws PorcupineException
        Processes a frame of the incoming audio stream and emits the detection result.
        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. Porcupine operates on single-channel audio.
        Returns:
        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.
      • getVersion

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