goPorcupine — Go Quick Start

  • Wake Word Detection
  • Local Voice Commands
  • Offline Keyword Spotting
  • Always Listening
  • Voice Activation
  • Linux
  • macOS
  • Windows
  • Go

Requirements

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

Compatibility

  • Linux (x86_64)
  • macOS (x86_64)
  • Windows (x86_64)

Cloning the Repository

If using SSH, clone the repository with:

git clone [email protected]:Picovoice/porcupine.git

If using HTTPS, then type:

git clone https://github.com/Picovoice/porcupine.git

Installation

The microphone demo uses malgo for cross-platform audio capture. It requires cgo, which on Windows may mean that you need to install a gcc compiler like Mingw to build it properly.

Usage

NOTE: The working directory for the following go commands is:

porcupine/demo/go

File Demo

The file demo uses Porcupine to scan for keywords in a wave file. The demo is mainly useful for quantitative performance benchmarking against a corpus of audio data. Porcupine processes a 16kHz, single-channel audio stream. If a stereo file is provided it only processes the first (left) channel. The following processes a file looking for instances of the phrase "Picovoice":

go run filedemo/porcupine_file_demo.go -input_audio_path "path/to/input.wav" -keywords picovoice

keywords is a shorthand for using built-in keyword files shipped with the package. The list of built-in keyword files can be seen in the usage string:

go run filedemo/porcupine_file_demo.go -h

To detect multiple phrases concurrently, provide them as comma-separated values. If the wake word is more than a single word, surround the argument in quotation marks:

go run filedemo/porcupine_file_demo.go -input_audio_path "path/to/input.wav" -keywords "grasshopper,hey siri"

To detect custom keywords (e.g. models created using Picovoice Console) use keyword_paths argument:

go run filedemo/porcupine_file_demo.go -input_audio_path "path/to/input.wav" \
-keyword_paths "/path/to/keyword/one.ppn,/path/to/keyword/two.ppn"

The sensitivity of the engine can be tuned per keyword using the sensitivities input argument:

go run filedemo/porcupine_file_demo.go -input_audio_path "path/to/input.wav" \
-keywords grasshopper,porcupine -sensitivities 0.3,0.6

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.

Microphone Demo

The microphone demo opens an audio stream from a microphone and detects utterances of a given wake word. The following opens the default microphone and detects occurrences of "Picovoice":

go run micdemo/porcupine_mic_demo.go -keywords picovoice

keywords is a shorthand for using built-in keyword files shipped with the package. The list of built-in keyword files can be seen in the usage string:

go run micdemo/porcupine_mic_demo.go -h

To detect multiple phrases concurrently provide them as comma-separated values. If the wake word is more than a single word, surround the argument in quotation marks:

go run filedemo/porcupine_file_demo.go -keywords "grasshopper,hey siri"

To detect custom keywords (e.g. models created using Picovoice Console) use keyword_paths argument:

go run micdemo/porcupine_mic_demo.go -keyword_paths "/path/to/keyword/one.ppn,/path/to/keyword/two.ppn"

It is possible that the default audio input device is not the one you wish to use. There are a couple of debugging facilities baked into the demo application to solve this. First, type the following into the console:

go run micdemo/porcupine_mic_demo.go -show_audio_devices

It provides information about various audio input devices on the box. On a is an example output from a Windows machine:

Capture Devices
0: Microphone Array (Realtek(R) Audio)
1: Microphone (USB Audio Device)

You can use the device index to specify which microphone to use for the demo. For instance, if you want to use the USB microphone in the above example, you can invoke the demo application as below:

go run micdemo/porcupine_mic_demo.go -keywords picovoice -audio_device_index 1

If the problem persists we suggest storing the recorded audio into a file for inspection. This can be achieved with:

go run micdemo/porcupine_mic_demo.go -keywords picovoice -audio_device_index 1 -output_path ./test.wav

If after listening to stored file there is no apparent problem detected please open an issue.

Custom Wake Word

You can create custom Porcupine wake word models using Picovoice Console.


Issue with this doc? Please let us know.