goPorcupine - Go API

API Reference for the Porcupine Go SDK (pkg.go.dev).


porcupine.BuiltInKeywords

var BuiltInKeywords []BuiltInKeyword

List of available built-in wake words.


porcupine.FrameLength

var FrameLength int

Number of audio samples per frame.


porcupine.SampleRate

var SampleRate int

Audio sample rate accepted by Porcupine.


porcupine.Version

var Version string

Porcupine version.


porcupine.BuiltInKeyword

type BuiltInKeyword string

Type representing a keyword that is packaged with the Porcupine SDK. Possible values are:

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"
)

porcupine.BuiltInKeyword.IsValid()

func (k BuiltInKeyword) IsValid() bool

Checks if a given BuiltInKeyword is valid.


porcupine.Porcupine

type Porcupine struct

Struct for the Porcupine Wake Word engine.


porcupine.Porcupine.AccessKey

var AccessKey string

AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).


porcupine.Porcupine.BuiltInKeywords

var BuiltInKeywords []BuiltInKeyword

List of built-in keywords to use.


porcupine.Porcupine.KeywordPaths

var KeywordPaths []string

Absolute paths to keyword model files.


porcupine.Porcupine.ModelPath

var ModelPath string

Absolute path to the file containing model parameters.


porcupine.Porcupine.Sensitivities

var Sensitivities []float32

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.


porcupine.Porcupine.Delete()

func (porcupine *Porcupine) Delete() error

Releases resources acquired by Porcupine.

Returns

  • error : Error produced by the Porcupine SDK. nil if no error was encountered.

porcupine.Porcupine.Init()

func (porcupine *Porcupine) Init() error

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

Returns

  • error : Error produced by the Porcupine SDK. nil if no error was encountered.

porcupine.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. The number of samples-per-frame can be obtained by calling .FrameLength. The incoming audio needs to have a sample rate equal to .SampleRate 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.

Parameters

  • pcm []int16 : A frame of audio samples.

Returns

  • int : Index of observed keyword at the end of the current frame. Indexing is 0-based and matches the ordering of keywords provided to the Porcupine struct. If no keyword is detected then it returns -1.
  • error : Error produced by the Porcupine SDK. nil if no error was encountered.

porcupine.PorcupineError

type PorcupineError struct

Custom error type for errors produced from the Porcupine Go SDK.


porcupine.PorcupineError.Error()

func (e *PorcupineError) Error() string

Formats the Porcupine error into a string.

Returns

  • string : Formatted error string.

porcupine.PvStatus

type PvStatus struct

Status return codes from the Porcupine library. Possible values are:

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
RUNTIME_ERROR PvStatus = 7
ACTIVATION_ERROR PvStatus = 8
ACTIVATION_LIMIT_REACHED PvStatus = 9
ACTIVATION_THROTTLED PvStatus = 10
ACTIVATION_REFUSED PvStatus = 11
)

Issue with this doc? Please let us know.