picovoice

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

Picovoice SDK for Go

Picovoice

Made in Vancouver, Canada by Picovoice

Picovoice is an end-to-end platform for building voice products on your terms. It enables creating voice experiences similar to Alexa and Google. But it entirely runs 100% on-device. Picovoice is

  • Private: Everything is processed offline. Intrinsically HIPAA and GDPR compliant.
  • Reliable: Runs without needing constant connectivity.
  • Zero Latency: Edge-first architecture eliminates unpredictable network delay.
  • Accurate: Resilient to noise and reverberation. It outperforms cloud-based alternatives by wide margins *.
  • Cross-Platform: Design once, deploy anywhere. Build using familiar languages and frameworks.

Compatibility

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

Installation

go get github.com/Picovoice/picovoice/sdk/go

Depending on your setup you also may need to run go mod tidy after in order to download transitive dependencies.

Usage

To create an instance of the engine with default parameters, use the NewPicovoice function. You must provide a Porcupine keyword file, a wake word detection callback function, a Rhino context file and a inference callback function. You must then make a call to Init().

. "github.com/Picovoice/picovoice/sdk/go"
rhn "github.com/Picovoice/rhino/binding/go"

keywordPath := "/path/to/keyword/file.ppn"
wakeWordCallback := func(){
    // let user know wake word detected
}

contextPath := "/path/to/keyword/file.rhn"
inferenceCallback := func(inference rhn.RhinoInference){
    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
    }
}

picovoice := NewPicovoice(keywordPath, 
    wakeWordCallback, 
    contextPath, 
    inferenceCallback)

err := picovoice.Init()
if err != nil {
    // handle error
}

Upon detection of wake word defined by keywordPath it starts inferring user's intent from the follow-on voice command within the context defined by the file located at contextPath. keywordPath is the absolute path to Porcupine wake word engine keyword file (with .ppn suffix). contextPath is the absolute path to Rhino Speech-to-Intent engine context file (with .rhn suffix). wakeWordCallback is invoked upon the detection of wake phrase and inferenceCallback is invoked upon completion of follow-on voice command inference.

When instantiated, valid sample rate can be obtained via SampleRate. Expected number of audio samples per frame is FrameLength. The engine accepts 16-bit linearly-encoded PCM and operates on single-channel audio.

func getNextFrameAudio() []int16{
    // get audio frame
}

for {
    err := picovoice.Process(getNextFrameAudio())
}

When done resources have to be released explicitly

picovoice.Delete()

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.

Demos

Check out the Picovoice Go demos here

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Required number of audio samples per frame.
	FrameLength = ppn.FrameLength

	// Required sample rate of input audio
	SampleRate = ppn.SampleRate

	// Version of Porcupine being used
	PorcupineVersion = ppn.Version

	// Version of Rhino being used
	RhinoVersion = rhn.Version

	// Picovoice version
	Version = fmt.Sprintf("1.1.0 (Porcupine v%s) (Rhino v%s)", PorcupineVersion, RhinoVersion)
)

Functions

This section is empty.

Types

type InferenceCallbackType

type InferenceCallbackType func(rhn.RhinoInference)

Callback for when Rhino has made an inference

type Picovoice

type Picovoice struct {

	// Path to Porcupine keyword file (.ppn)
	KeywordPath string

	// Function to be called once the wake word has been detected
	WakeWordCallback WakeWordCallbackType

	// Path to Rhino context file (.rhn)
	ContextPath string

	// Function to be called once Rhino has an inference ready
	InferenceCallback InferenceCallbackType

	// Path to Porcupine model file (.pv)
	PorcupineModelPath string

	// Sensitivity value for detecting keyword. The value should be a number within [0, 1]. A
	// higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
	PorcupineSensitivity float32

	// Path to Rhino model file (.pv)
	RhinoModelPath string

	// Inference sensitivity. A higher sensitivity value results in
	// fewer misses at the cost of (potentially) increasing the erroneous inference rate.
	// Sensitivity should be a floating-point number within 0 and 1.
	RhinoSensitivity float32

	// Once initialized, stores the source of the Rhino context in YAML format. Shows the list of intents,
	// which expressions map to those intents, as well as slots and their possible values.
	ContextInfo string
	// contains filtered or unexported fields
}

Picovoice struct

func NewPicovoice

func NewPicovoice(keywordPath string,
	wakewordCallback WakeWordCallbackType,
	contextPath string,
	inferenceCallback InferenceCallbackType) Picovoice

Returns a Picovoice stuct with default parameters

func (*Picovoice) Delete

func (picovoice *Picovoice) Delete() error

Releases resouces aquired by Picovoice

func (*Picovoice) Init

func (picovoice *Picovoice) Init() error

Init function for Picovoice. Must be called before attempting process.

func (*Picovoice) Process

func (picovoice *Picovoice) Process(pcm []int16) error

Process a frame of pcm audio with the Picovoice platform. Invokes user-defined callbacks upon detection of wake word and completion of follow-on command inference

type PvStatus

type PvStatus int

PvStatus descibes error codes returned from native code

const (
	SUCCESS          PvStatus = 0
	OUT_OF_MEMORY    PvStatus = 1
	IO_ERROR         PvStatus = 2
	INVALID_ARGUMENT PvStatus = 3
	STOP_ITERATION   PvStatus = 4
	KEY_ERROR        PvStatus = 5
	INVALID_STATE    PvStatus = 6
)

type WakeWordCallbackType

type WakeWordCallbackType func()

Callback for when a wake word has been detected

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL