Class Rhino


  • public class Rhino
    extends java.lang.Object
    Java binding for Rhino Speech-to-Intent engine. It directly infers the user's intent from spoken commands in real-time. Rhino processes incoming audio in consecutive frames and indicates if the inference is finalized. When finalized, the inferred intent can be retrieved as structured data in the form of an intent string and pairs of slots and values. 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. Rhino operates on single-channel audio.
    • Nested Class Summary

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

      Fields 
      Modifier and Type Field Description
      static java.lang.String LIBRARY_PATH  
      static java.lang.String MODEL_PATH  
    • Constructor Summary

      Constructors 
      Constructor Description
      Rhino​(java.lang.String accessKey, java.lang.String libraryPath, java.lang.String modelPath, java.lang.String contextPath, float sensitivity, float endpointDurationSec, boolean requireEndpoint)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete()
      Releases resources acquired by Rhino.
      java.lang.String getContextInformation()
      Getter for context information.
      int getFrameLength()
      Getter for number of audio samples per frame.
      RhinoInference getInference()
      Gets inference result from Rhino.
      int getSampleRate()
      Getter for audio sample rate accepted by Picovoice.
      java.lang.String getVersion()
      Getter for version.
      boolean process​(short[] pcm)
      Processes a frame of audio and emits a flag indicating if the inference is finalized.
      void reset()
      Resets the internal state of Rhino.
      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
    • Constructor Detail

      • Rhino

        public Rhino​(java.lang.String accessKey,
                     java.lang.String libraryPath,
                     java.lang.String modelPath,
                     java.lang.String contextPath,
                     float sensitivity,
                     float endpointDurationSec,
                     boolean requireEndpoint)
              throws RhinoException
        Constructor.
        Parameters:
        accessKey - AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
        libraryPath - Absolute path to the native Rhino library.
        modelPath - Absolute path to the file containing 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.
        sensitivity - 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 preemptively 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).
        Throws:
        RhinoException - If there is an error while initializing Rhino.
    • Method Detail

      • setSdk

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

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

        public boolean process​(short[] pcm)
                        throws RhinoException
        Processes a frame of audio and emits a flag indicating if the inference is finalized. When finalized, getInference() should be called to retrieve the intent and slots, if the spoken command is considered valid.
        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. Furthermore, Rhino operates on single channel audio.
        Returns:
        Flag indicating whether the engine has finalized intent extraction.
        Throws:
        RhinoException - if there is an error while processing the audio frame.
      • reset

        public void reset()
                   throws RhinoException
        Resets the internal state of Rhino. It should be called before the engine can be used to infer intent from a new stream of audio.
        Throws:
        RhinoException - if reset fails.
      • getInference

        public RhinoInference getInference()
                                    throws RhinoException
        Gets inference result from Rhino. If the spoken command was understood, it includes the specific intent name that was inferred, and (if applicable) slot keys and specific slot values. Should only be called after the process function returns true, otherwise Rhino has not yet reached an inference conclusion.
        Returns:
        The result of inference as a RhinoInference object.
        Throws:
        RhinoException - if inference retrieval fails.
      • getContextInformation

        public java.lang.String getContextInformation()
                                               throws RhinoException
        Getter for context information.
        Returns:
        Context information.
        Throws:
        RhinoException
      • 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.
      • getVersion

        public java.lang.String getVersion()
        Getter for version.
        Returns:
        Version.