javaPorcupine — Java Quick Start

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

Requirements

  • Java 11+

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

You can get the latest Java demo executable JARs here.

If you wish, you can build the demos from source by opening the project with the IntelliJ IDE. Select "Build > Build Project" to build the two demo classes or "Build > Build Artifacts" to create the executable JARs.

Usage

NOTE: the working directory for java commands is:

porcupine/demo/java/bin

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

java -jar porcupine-file-demo.jar -i ${AUDIO_PATH} -k picovoice

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

java -jar porcupine-file-demo.jar -h

To detect multiple phrases concurrently provide them as separate arguments:

java -jar porcupine-file-demo.jar -i ${AUDIO_PATH} -k grasshopper porcupine

To detect non-default keywords (e.g. models created using Picovoice Console) use the -kp or --keyword_paths argument:

java -jar porcupine-file-demo.jar -i ${AUDIO_PATH} -kp ${KEYWORD_PATH_ONE} ${KEYWORD_PATH_TWO}

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

java -jar porcupine-file-demo.jar -i ${AUDIO_PATH} -k grasshopper porcupine -s 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

This 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":

java -jar porcupine-mic-demo.jar -k picovoice

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

java -jar porcupine-mic-demo.jar -h

To detect multiple phrases concurrently provide them as separate arguments:

java -jar porcupine-mic-demo.jar -k picovoice porcupine

To detect non-default keywords (e.g. models created using Picovoice Console) use the -kp or --keyword_paths argument:

java -jar porcupine-mic-demo.jar -kp ${KEYWORD_PATH_ONE} ${KEYWORD_PATH_TWO}

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:

java -jar porcupine-mic-demo.jar -sd

It provides information about various audio input devices on the box. On a Windows PC, this is the output:

Available input devices:
Device 4: Microphone Array (Realtek(R) Au
Device 5: Microphone Headset USB

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

java -jar porcupine-mic-demo.jar -k picovoice -di 5

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

java -jar porcupine-mic-demo.jar -k picovoice -di 5 -o ./test.wav

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


Issue with this doc? Please let us know.