Rhino - Python API

  • Speech-to-Intent Engine
  • Domain Specific NLU
  • Offline SLU
  • Local Voice Recognition
  • Raspberry Pi
  • ARM Linux
  • Linux
  • Mac
  • Windows
  • Python

This document outlines how to integrate Rhino Spech-to-Intent engine within an application using its Python API.

Requirements

  • Python3.

Installation

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

Integration

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.pv
context_file_path = ... # absolute path to context file for the domain of interest
rhino = 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():
pass
while 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 values
else:
# add code to handle unsupported commands
pass
rhino.reset()

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

rhino.delete()

Creating Custom Contexts

Enterprises who are engaged with Picovoice can create custom context models using Picovoice Console.