Porcupine Wake Word
Python API
API Reference for the Python Porcupine SDK (PyPI).
pvporcupine.available_devices()
Lists all available devices that Porcupine can use for inference. Each entry in the list can be the device argument
of create() factory method or Porcupine constructor.
Parameters
library_pathOptional[str] : Absolute path to Porcupine's dynamic library. If not set it will be set to the default location.
Returns
- Sequence[str]: List of all available devices that Porcupine can use for inference.
Throws
pvporcupine.create()
Factory method for Porcupine Wake Word engine.
Parameters
access_keystr : AccessKey obtained from Picovoice Console.library_pathOptional[str] : Absolute path to Porcupine's dynamic library. If not set it will be set to the default location.model_pathOptional[str] : Absolute path to the file containing model parameters. 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.keyword_pathsOptional[List[str]] : Absolute paths to keyword model files. If not set it will be populated fromkeywordsargument.keywordsOptional[List[str]] : List of built-in keywords (phrases) for detection. Ifkeyword_pathsis set then this argument will be ignored.sensitivitiesOptional[List[float]] : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate. If not set 0.5 will be used.
Returns
Porcupine: An instance of Porcupine Wake Word engine.
Throws
pvporcupine.Porcupine
Class for the Porcupine Wake Word engine.
Porcupine 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.
pvporcupine.Porcupine.version
The version string of the Porcupine library.
pvporcupine.Porcupine.frame_length
The number of audio samples per frame that Porcupine accepts.
pvporcupine.Porcupine.sample_rate
The audio sample rate the Porcupine accepts.
pvporcupine.Porcupine.__init__()
__init__ method for Porcupine Wake Word engine.
Parameters
access_keystr : AccessKey obtained from Picovoice Console.library_pathstr : Absolute path to Porcupine's dynamic library.model_pathstr : Absolute path to the file containing model parameters.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.keyword_pathsList[str] : Absolute paths to keyword model files.sensitivitiesList[float] : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
Returns
Porcupine: An instance of Porcupine Wake Word engine.
Throws
pvporcupine.Porcupine.delete()
Releases resources acquired by Porcupine
pvporcupine.Porcupine.process()
Processes a frame of the incoming audio stream and emits the detection result.
The number of samples per frame can be attained by calling .frame_length.
The incoming audio needs to have a sample rate equal to .sample_rate and be 16-bit linearly-encoded.
Porcupine operates on single-channel audio.
Parameters
pcmList[int] : A frame of audio samples.
Returns
int: Index of observed keyword at the end of the current frame. Indexing is 0-based and matches the ordering of keyword models provided to the constructor. If no keyword is detected then it returns -1.
Throws
pvporcupine.PorcupineError
Error thrown if an error occurs within Porcupine Wake Word engine.
Exceptions