pythonPorcupine - Python API

  • End-to-End Voice Platform
  • Offline Voice Recognition
  • Local Speech Recognition
  • Speech-to-Intent
  • Domain-Specific NLU
  • Wake Word Detection
  • Raspberry Pi
  • BeagleBone
  • Linux
  • macOS
  • Windows
  • Python

Requirements

  • Python 3
  • PIP

Compatibility

  • Linux (x86_64)
  • macOS (x86_64)
  • Windows (x86_64)
  • Raspberry Pi (all variants)
  • BeagleBone.

Installation

pip3 install pvporcupine

Usage

The PIP package exposes a factory method to create instances of the engine:

import pvporcupine
handle = pvporcupine.create(keywords=['picovoice', 'bumblebee'])

keywords argument is a shorthand for accessing default keyword files shipped with the library. The default keyword files available can be retrieved via:

import pvporcupine
print(pvporcupine.KEYWORDS)

If you wish to use a non-default keyword file you need to identify its path as below

import pvporcupine
handle = pvporcupine.create(keyword_paths=['path/to/non/default/keyword/file'])

When initialized, valid sample rate can be obtained using handle.sample_rate. Expected frame length (number of audio samples in an input array) is handle.frame_length. The object can be used to monitor incoming audio as below.

def get_next_audio_frame():
pass
while True:
keyword_index = handle.process(get_next_audio_frame())
if keyword_index >= 0:
# detection event logic/callback
pass

Finally, when done be sure to explicitly release the resources as the binding class does not rely on the garbage collector.

handle.delete()

Custom Wake Word

You can create custom Porcupine wake word models using Picovoice Console.


Issue with this doc? Please let us know.