Picovoice Platform — Python API
This document outlines how to integrate Picovoice platform within an application using its Python API.
- Linux (x86_64)
- macOS (x86_64)
- Windows (x86_64)
- Raspberry Pi (all variants)
pip3 install picovoice
Create a new instance of Picovoice runtime engine
from picovoice import Picovoicekeyword_path = ...def wake_word_callback():passcontext_path = ...def inference_callback(inference):# `inference` exposes three immutable fields:# (1) `is_understood`# (2) `intent`# (3) `slots`passhandle = Picovoice(keyword_path=keyword_path,wake_word_callback=wake_word_callback,context_path=context_path,inference_callback=inference_callback)
handle is an instance of Picovoice runtime engine that detects utterances of wake phrase defined in the file located at
keyword_path. Upon detection of wake word it starts inferring user's intent from the follow-on voice command within
the context defined by the file located at
keyword_path is the absolute path to
Porcupine wake word engine keyword file (with
context_path is the absolute path to Rhino Speech-to-Intent engine context file
wake_word_callback is invoked upon the detection of wake phrase and
invoked upon completion of follow-on voice command inference.
When instantiated, valid sample rate can be obtained via
handle.sample_rate. Expected number of audio samples per
handle.frame_length. The engine accepts 16-bit linearly-encoded PCM and operates on single-channel audio.
def get_next_audio_frame():passwhile True:handle.process(get_next_audio_frame())
When done resources have to be released explicitly