Porcupine - Python API
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 pvporcupinehandle = 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 pvporcupineprint(pvporcupine.KEYWORDS)
If you wish to use a non-default keyword file you need to identify its path as below
import pvporcupinehandle = 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():passwhile True:keyword_index = handle.process(get_next_audio_frame())if keyword_index >= 0:# detection event logic/callbackpass
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.
Non-English Wake Words
In order to detect non-English wake words you need to use the corresponding model file. The model files for all supported languages are available here.