pythonPicovoice Platform — 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
  • Nvidia Jetson
  • Linux
  • macOS
  • Windows
  • Python

This document outlines how to integrate Picovoice platform within an application using its Python API.

Requirements

  • Python 3
  • PIP

Compatibility

  • Linux (x86_64)
  • macOS (x86_64)
  • Windows (x86_64)
  • Raspberry Pi (all variants)
  • Nvidia Jetson (Nano)
  • BeagleBone

Installation

pip3 install picovoice

Usage

Create a new instance of Picovoice runtime engine

from picovoice import Picovoice
keyword_path = ...
def wake_word_callback():
pass
context_path = ...
def inference_callback(inference):
# `inference` exposes three immutable fields:
# (1) `is_understood`
# (2) `intent`
# (3) `slots`
pass
handle = 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 context_path. keyword_path is the absolute path to Porcupine wake word engine keyword file (with .ppn suffix). context_path is the absolute path to Rhino Speech-to-Intent engine context file (with .rhn suffix). wake_word_callback is invoked upon the detection of wake phrase and inference_callback is 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 frame is handle.frame_length. The engine accepts 16-bit linearly-encoded PCM and operates on single-channel audio.

def get_next_audio_frame():
pass
while True:
handle.process(get_next_audio_frame())

When done resources have to be released explicitly

handle.delete()

Custom Wake Word & Context

You can create custom Porcupine wake word and Rhino context models using Picovoice Console

Non-English Models

In order to detect wake words and run inference in other languages you need to use the corresponding model file. The model files for all supported languages are available here and here.


Issue with this doc? Please let us know.