Class Cobra


  • public class Cobra
    extends java.lang.Object
    Android binding for Cobra voice activity detection (VAD) engine. It detects speech signals within an incoming stream of audio in real-time. It processes incoming audio in consecutive frames and for each frame emits the probability of voice activity. 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. Cobra operates on single-channel audio.
    • Constructor Summary

      Constructors 
      Constructor Description
      Cobra​(java.lang.String accessKey)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete()
      Releases resources acquired by Cobra.
      int getFrameLength()
      Getter for required number of audio samples per frame.
      int getSampleRate()
      Getter for required audio sample rate.
      java.lang.String getVersion()
      Getter for Cobra version.
      float 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
    • Constructor Detail

      • Cobra

        public Cobra​(java.lang.String accessKey)
              throws CobraException
        Constructor.
        Parameters:
        accessKey - AccessKey obtained from Picovoice Console
        Throws:
        CobraException - if there is an error while initializing Cobra.
    • Method Detail

      • setSdk

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

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

        public float process​(short[] pcm)
                      throws CobraException
        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. Furthermore, Cobra operates on single channel audio only.
        Returns:
        Probability of voice activity. It is a floating-point number within [0, 1].
        Throws:
        CobraException - if there is an error while processing the audio frame.
      • getFrameLength

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

        public int getSampleRate()
        Getter for required audio sample rate.
        Returns:
        Required audio sample rate.
      • getVersion

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