Package ai.picovoice.cobra
Class Cobra
- java.lang.Object
-
- ai.picovoice.cobra.Cobra
-
public class Cobra extends java.lang.ObjectAndroid 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 callinggetFrameLength(). The incoming audio needs to have a sample rate equal togetSampleRate()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 Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()Releases resources acquired by Cobra.intgetFrameLength()Getter for required number of audio samples per frame.intgetSampleRate()Getter for required audio sample rate.java.lang.StringgetVersion()Getter for Cobra version.floatprocess(short[] pcm)Processes a frame of the incoming audio stream and emits the detection result.
-
-
-
Constructor Detail
-
Cobra
public Cobra(java.lang.String accessKey) throws CobraExceptionConstructor.- Parameters:
accessKey- AccessKey obtained from Picovoice Console- Throws:
CobraException- if there is an error while initializing Cobra.
-
-
Method Detail
-
delete
public void delete()
Releases resources acquired by Cobra.
-
process
public float process(short[] pcm) throws CobraExceptionProcesses 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 callinggetFrameLength(). The incoming audio needs to have a sample rate equal togetSampleRate()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.
-
-