Cobra Voice Activity Detection
Python API
API Reference for the Cobra Python SDK (PyPI).
pvcobra.create()
Factory method for the Cobra voice activity detection (VAD) engine.
Parameters
access_keystr : AccessKey obtained from Picovoice Console.library_pathOptional[str] : Absolute path to Cobra's dynamic library. If not set, it will be set to the default location.deviceOptional[str] : String representation of the device (e.g., CPU or GPU) to use. If set tobest, the most suitable device is selected automatically. If set togpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument togpu:${GPU_INDEX}, where${GPU_INDEX}is the index of the target GPU. If set tocpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument tocpu:${NUM_THREADS}, where${NUM_THREADS}is the desired number of threads.
Returns
Cobra: An instance of Cobra VAD engine.
pvcobra.available_devices()
Lists all available devices that Cobra can use for inference. Each entry in the list can be the device argument
of create() factory method or Cobra constructor.
Parameters
library_pathOptional[str] : Absolute path to Cobra's dynamic library. If not set it will be set to the default location.
Returns
- Sequence[str]: List of all available devices that Cobra can use for inference.
Throws
pvcobra.Cobra
Class for the Cobra VAD engine.
Cobra can be initialized either using the module level create() function
or directly using the class __init__() method.
Resources should be cleaned when you are done using the delete() method.
pvcobra.Cobra.frame_length
The number of audio samples per frame that Cobra accepts.
pvcobra.Cobra.sample_rate
The audio sample rate the Cobra accepts.
pvcobra.Cobra.version
The Cobra library version string.
pvcobra.Cobra.__init__()
__init__ method for Cobra VAD engine.
Parameters
access_keystr : AccessKey obtained from Picovoice Console.library_pathstr : Absolute path to Cobra's dynamic library.devicestr : String representation of the device (e.g., CPU or GPU) to use. If set tobest, the most suitable device is selected automatically. If set togpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument togpu:${GPU_INDEX}, where${GPU_INDEX}is the index of the target GPU. If set tocpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument tocpu:${NUM_THREADS}, where${NUM_THREADS}is the desired number of threads.
Returns
Cobra: An instance of Cobra VAD engine.
Throws
pvcobra.Cobra.delete()
Releases resources acquired by Cobra.
pvcobra.Cobra.process()
Processes a frame of the incoming audio stream and emits the detection result.
The required number of samples-per-frame can be obtained by calling .frame_length.
The incoming audio needs to have a sample rate equal to .sample_rate and be 16-bit linearly-encoded.
Cobra operates on single-channel audio.
Parameters
pcmList[int] : A frame of audio samples.
Returns
float: Probability of voice activity. It is a floating-point number within [0, 1].
Throws
pvcobra.CobraError
Error thrown if an error occurs within Cobra VAD engine.
Exceptions