porcupine

package module
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: Apache-2.0 Imports: 11 Imported by: 3

README

Porcupine Wake Word Engine

Made in Vancouver, Canada by Picovoice

Porcupine is a highly-accurate and lightweight wake word engine. It enables building always-listening voice-enabled applications. It is

  • using deep neural networks trained in real-world environments.
  • compact and computationally-efficient. It is perfect for IoT.
  • cross-platform. Raspberry Pi, BeagleBone, Android, iOS, Linux (x86_64), macOS (x86_64), Windows (x86_64), and web browsers are supported. Additionally, enterprise customers have access to ARM Cortex-M SDK.
  • scalable. It can detect multiple always-listening voice commands with no added runtime footprint.
  • self-service. Developers can train custom wake word models using Picovoice Console.

Compatibility

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

Installation

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

Usage

To create an instance of the engine you first creat a Porcupine struct with the configuration parameters for the wake word engine and then make a call to .Init().

import . "github.com/Picovoice/porcupine/binding/go"

porcupine := Porcupine{BuiltInKeywords: []BuiltInKeyword{PICOVOICE}}
err := porcupine.Init()
if err != nil {
    // handle init fail
}

In the above example, we've initialzed the engine to detect the built-in wake word "Picovoice". Built-in keywords are constants in the package with the BuiltInKeyword type.

Porcupine can detect multiple keywords concurrently

porcupine := Porcupine{BuiltInKeywords: []BuiltInKeyword{PICOVOICE, BUMBLEBEE}}
err := porcupine.Init()

To detect non-default keywords, use KeywordPaths parameter instead

porcupine := Porcupine{KeywordPaths: []string{"/path/to/keyword.ppn"}}
err := porcupine.Init()

The sensitivity of the engine can be tuned per keyword using the sensitivities parameter

porcupine := Porcupine{
    BuiltInKeywords: []BuiltInKeyword{PICOVOICE, BUMBLEBEE}
    Sensitivities: []float32{0.4, 0.9}}
err := porcupine.Init()

Sensitivity is the parameter that enables trading miss rate for the false alarm rate. It is a floating point number within [0, 1]. A higher sensitivity reduces the miss rate at the cost of increased false alarm rate.

When initialized, the valid sample rate is given by SampleRate. Expected frame length (number of audio samples in an input array) is given by FrameLength. The engine accepts 16-bit linearly-encoded PCM and operates on single-channel audio.

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

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

for {
    keywordIndex, err := porcupine.Process(getNextFrameAudio())
    if keywordIndex >= 0 {
        // wake word detected!
    }
}

When done resources have to be released explicitly.

porcupine.Delete()

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

Non-English Wake Words

In order to detect non-English wake words you need to use the corresponding model file. The model files for all supported languages are available here.

Demos

Check out the Porcupine Go demos here

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Number of audio samples per frame.
	FrameLength = nativePorcupine.nativeFrameLength()

	// Audio sample rate accepted by Picovoice.
	SampleRate = nativePorcupine.nativeSampleRate()

	// Porcupine version
	Version = nativePorcupine.nativeVersion()
)

List of available built-in wake words

Functions

This section is empty.

Types

type BuiltInKeyword

type BuiltInKeyword string

BuiltInKeyword Type

const (
	ALEXA       BuiltInKeyword = "alexa"
	AMERICANO   BuiltInKeyword = "americano"
	BLUEBERRY   BuiltInKeyword = "blueberry"
	BUMBLEBEE   BuiltInKeyword = "bumblebee"
	COMPUTER    BuiltInKeyword = "computer"
	GRAPEFRUIT  BuiltInKeyword = "grapefruit"
	GRASSHOPPER BuiltInKeyword = "grasshopper"
	HEY_GOOGLE  BuiltInKeyword = "hey google"
	HEY_SIRI    BuiltInKeyword = "hey siri"
	JARVIS      BuiltInKeyword = "jarvis"
	OK_GOOGLE   BuiltInKeyword = "ok google"
	PICOVOICE   BuiltInKeyword = "picovoice"
	PORCUPINE   BuiltInKeyword = "porcupine"
	TERMINATOR  BuiltInKeyword = "terminator"
)

Available built-in wake words constants

func (BuiltInKeyword) IsValid

func (k BuiltInKeyword) IsValid() bool

Checks if a given BuiltInKeyword is valid

type Porcupine

type Porcupine struct {

	// Absolute path to the file containing model parameters.
	ModelPath string

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

	// List of built-in keywords to use.
	BuiltInKeywords []BuiltInKeyword

	// Absolute paths to keyword model files.
	KeywordPaths []string
	// contains filtered or unexported fields
}

Porcupine struct

func (*Porcupine) Delete

func (porcupine *Porcupine) Delete() error

Releases resources acquired by Porcupine.

func (*Porcupine) Init

func (porcupine *Porcupine) Init() (err error)

Init function for Porcupine. Must be called before attempting process

func (*Porcupine) Process

func (porcupine *Porcupine) Process(pcm []int16) (keywordIndex int, err error)

Processes a frame of the incoming audio stream and emits the detection result. Frame of audio The number of samples per frame can be attained by calling `.FrameLength`. The incoming audio needs to have a sample rate equal to `.Sample` and be 16-bit linearly-encoded. Porcupine operates on single-channel audio. Returns a 0 based index if keyword was detected in frame. Returns -1 if no detection was made.

type PvStatus

type PvStatus int

PvStatus type

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
)

Possible status return codes from the Porcupine library

Jump to

Keyboard shortcuts

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