Speech-to-Intent Engine - Python API
This document outlines how to integrate Rhino Spech-to-Intent engine within an application using its Python API.
If using SSH, clone the repository with:
git clone --recurse-submodules [email protected]:Picovoice/rhino.git
If using HTTPS, then type:
git clone --recurse-submodules https://github.com/Picovoice/rhino.git
binding/python/rhino.py provides a Python binding for Rhino library. Below is a quick demonstration of how to initialize an instance:
library_path = ... # absolute path to Rhino's dynamic library under lib/model_file_path = ... # available at lib/common/rhino_params.pvcontext_file_path = ... # absolute path to context file for the domain of interestrhino = Rhino(library_path=library_path,model_path=model_file_path,context_path=context_file_path)
When initialized, valid sample rate can be obtained using
rhino.sample_rate. Expected frame length
(number of audio samples in an input array) is
rhino.frame_length. The object can be used to infer intent from spoken
commands as below:
def get_next_audio_frame():passwhile True:is_finalized = rhino.process(get_next_audio_frame())if is_finalized:if rhino.is_understood():intent, slot_values = rhino.get_intent()# add code to take action based on inferred intent and slot valueselse:# add code to handle unsupported commandspassrhino.reset()
Finally, when done, be sure to explicitly release the resources; the binding class does not rely on the garbage collector.
Creating Custom Contexts
Enterprises who are engaged with Picovoice can create custom context models using Picovoice Console.