goRhino - Go API

  • Speech-to-Intent Engine
  • Domain Specific NLU
  • Offline NLU
  • Local Voice Recognition
  • Linux
  • macOS
  • Windows
  • Go

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

Requirements

  • Go SDK 1.16+
  • On Windows you need to have a gcc (like Mingw) in your path

Compatibility

  • Runs on Linux (x86_64), macOS (x86_64) and Windows (x86_64)
  • Go 1.16+

Installation

You can install the latest version of Rhino into your Go module by running:

go get github.com/Picovoice/rhino/binding/go

Usage

To create an instance of the engine with default parameters, pass a path to a Rhino context file (.rhn) to the NewRhino function and then make a call to .Init().

import . "github.com/Picovoice/rhino/binding/go"
rhino = NewRhino("/path/to/context/file.rhn")
err := rhino.Init()
if err != nil {
// handle error
}

The context file is a Speech-to-Intent context created either using Picovoice Console or one of the default contexts available on Rhino's GitHub repository.

The sensitivity of the engine can be tuned using the sensitivity parameter. It is a floating point number within [0, 1]. A higher sensitivity value results in fewer misses at the cost of (potentially) increasing the erroneous inference rate. You can also override the default Rhino model (.pv), which is needs to be done when using a non-English context.

To override these parameters, you can create a Rhino struct directly and then call Init():

import . "github.com/Picovoice/rhino/binding/go"
rhino = Rhino{
ContextPath: "/path/to/context/file.rhn",
Sensitivity: 0.7,
ModelPath: "/path/to/rhino/params.pv"}
err := rhino.Init()
if err != nil {
// handle error
}

Once initialized, you can start passing in frames of audio for processing. The sample rate that is required by the engine is given by SampleRate and number of samples per frame is FrameLength.

To feed audio into Rhino, use the Process function in your capture loop. You must have called Init() before calling Process.

func getNextFrameAudio() []int16{
// get audio frame
}
for {
isFinalized, err := rhino.Process(getNextFrameAudio())
if isFinalized {
inference, err := rhino.GetInference()
if inference.IsUnderstood {
intent := inference.Intent
slots := inference.Slots
// add code to take action based on inferred intent and slot values
} else {
// add code to handle unsupported commands
}
}
}

When done resources have to be released explicitly.

rhino.Delete()

Using a defer call to Delete() after Init() is also a good way to ensure cleanup.

Custom Context

You can create custom Rhino context models using Picovoice Console.

Non-English Contexts

In order to run inference on non-English contexts you need to use the corresponding model file (.pv extension). The model files for all supported languages are available here.


Issue with this doc? Please let us know.