pythonPorcupine - Python API

API Reference for the Python Porcupine SDK (PyPI).


pvporcupine.create()

def create(
access_key: str,
library_path: Optional[str] = None,
model_path: Optional[str] = None,
keyword_paths: Optional[List[str]] = None,
keywords: Optional[List[str]] = None,
sensitivities: Optional[List[float]] = None) -> Porcupine

Factory method for Porcupine Wake Word engine.

Parameters

  • access_key str : AccessKey obtained from Picovoice Console.
  • library_path Optional[str] : Absolute path to Porcupine's dynamic library. If not set it will be set to the default location.
  • model_path Optional[str] : Absolute path to the file containing model parameters. If not set it will be set to the default location.
  • keyword_paths Optional[List[str]] : Absolute paths to keyword model files. If not set it will be populated from keywords argument.
  • keywords Optional[List[str]] : List of built-in keywords (phrases) for detection. If keyword_paths is set then this argument will be ignored.
  • sensitivities Optional[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 Porcupine(object)

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

self.version: str

The version string of the Porcupine library.


pvporcupine.Porcupine.frame_length

self.frame_length: int

The number of audio samples per frame that Porcupine accepts.


pvporcupine.Porcupine.sample_rate

self.sample_rate: int

The audio sample rate the Porcupine accepts.


pvporcupine.Porcupine.__init__()

def __init__(
self,
access_key: str,
library_path: str,
model_path: str,
keyword_paths: List[str],
sensitivities: List[float]) -> Porcupine

__init__ method for Porcupine Wake Word engine.

Parameters

  • access_key str : AccessKey obtained from Picovoice Console.
  • library_path str : Absolute path to Porcupine's dynamic library.
  • model_path str : Absolute path to the file containing model parameters.
  • keyword_paths List[str] : Absolute paths to keyword model files.
  • sensitivities 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.

Returns

  • Porcupine: An instance of Porcupine Wake Word engine.

Throws


pvporcupine.Porcupine.delete()

def delete(self)

Releases resources acquired by Porcupine


pvporcupine.Porcupine.process()

def process(self, pcm: List[int]) -> int

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

  • pcm List[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

class PorcupineError(Exception)

Error thrown if an error occurs within Porcupine Wake Word engine.

Exceptions

class PorcupineActivationError(PorcupineError)
class PorcupineActivationLimitError(PorcupineError)
class PorcupineActivationRefusedError(PorcupineError)
class PorcupineActivationThrottledError(PorcupineError)
class PorcupineIOError(PorcupineError)
class PorcupineInvalidArgumentError(PorcupineError)
class PorcupineInvalidStateError(PorcupineError)
class PorcupineKeyError(PorcupineError)
class PorcupineMemoryError(PorcupineError)
class PorcupineRuntimeError(PorcupineError)
class PorcupineStopIterationError(PorcupineError)

Issue with this doc? Please let us know.