Cobra Voice Activity Detection
Web API
API Reference for the Cobra Web SDK (npm).
Cobra
Class for the Cobra VAD engine.
Cobra.create()
Creates an instance of the Cobra voice activity detection (VAD) engine.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.voiceProbabilityCallback
(voiceProbability: number) => void : User-defined callback invoked when a frame of audio is processed. The callback provides a single parameter 'voiceProbability': a floating-point number within [0, 1].options
CobraOptions : Optional configuration arguments.
Returns
Cobra
: An instance of the Cobra engine.
Cobra.process()
Processes a frame of audio. The required sample rate can be retrieved from 'sampleRate' and the length of frame (number of audio samples per frame) can be retrieved from 'frameLength'. The audio must be single-channel and 16-bit linearly-encoded.
The voice probability result will be supplied via the voiceProbabilityCallback
that was passed into Cobra.create()
.
Parameters
pcm
Int16Array : A frame of audio samples.
Cobra.release()
Releases resources acquired by the Cobra Web SDK.
Cobra.frameLength
Number of audio samples per frame.
Cobra.sampleRate
Audio sample rate accepted by Cobra.
Cobra.version
Cobra version string.
CobraOptions
Cobra options type.
processErrorCallback
boolean : User-defined callback invoked if any error happens while processing the audio stream. Its only input argument is the error message. NOTE: This is only used byCobraWorker
.
CobraWorker
A class for running the Cobra VAD engine as a web worker thread.
CobraWorker.create()
Creates an instance of CobraWorker
.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.voiceProbabilityCallback
(voiceProbability: number) => void : User-defined callback invoked when a frame of audio is processed. The callback provides a single parameter 'voiceProbability': a floating-point number within [0, 1].options
CobraOptions : Optional configuration arguments.
Returns
CobraWorker
: An instance ofCobraWorker
.
CobraWorker.process()
Processes a frame of audio. The required sample rate can be retrieved from 'sampleRate' and the length of frame (number of audio samples per frame) can be retrieved from 'frameLength'. The audio must be single-channel and 16-bit linearly-encoded.
The voice probability result will be supplied via the voiceProbabilityCallback
that was passed into CobraWorker.create()
.
Parameters
pcm
Int16Array : A frame of audio samples.
CobraWorker.release()
Releases resources acquired by the Cobra Web SDK.
CobraWorker.terminate()
Force terminates the instance of CobraWorker
.
CobraWorker.frameLength
Number of audio samples per frame.
CobraWorker.sampleRate
Audio sample rate accepted by Cobra.
CobraWorker.version
Cobra version string.
CobraError
Error thrown if an error occurs within Cobra
VAD engine.
Errors: