javaPicovoice Platform — Java API

  • End-to-End Voice Platform
  • Offline Voice Recognition
  • Local Speech Recognition
  • Speech-to-Intent
  • Domain-Specific NLU
  • Wake Word Detection
  • Linux
  • macOS
  • Windows
  • Java

This document outlines how to integrate Picovoice platform within an application using its Java API.

Requirements

  • Java 11+

Compatibility

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

Installation

You can add the Picovoice Java SDK by downloading and referencing the latest Picovoice JAR.

Build

To build from source, we recommend using the IntelliJ IDE. Open the .iml file with IntelliJ and click "Build > Build Project" to build or "Build > Build Artifacts" to package as a JAR file.

Usage

The easiest way to create an instance of the engine is with the Picovoice Builder:

import ai.picovoice.picovoice.*;
String keywordPath = "/absolute/path/to/keyword.ppn"
PicovoiceWakeWordCallback wakeWordCallback = () -> {..};
String contextPath = "/absolute/path/to/context.rhn"
PicovoiceInferenceCallback inferenceCallback = inference -> {
// `inference` exposes three getters:
// (1) `getIsUnderstood()`
// (2) `getIntent()`
// (3) `getSlots()`
// ..
};
try{
Picovoice handle = new Picovoice.Builder()
.setKeywordPath(keywordPath)
.setWakeWordCallback(wakeWordCallback)
.setContextPath(contextPath)
.setInferenceCallback(inferenceCallback)
.build();
} catch (PicovoiceException e) { }

handle is an instance of Picovoice runtime engine that detects utterances of wake phrase defined in the file located at keywordPath. Upon detection of wake word 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 handle.getSampleRate(). Expected number of audio samples per frame is handle.getFrameLength(). The engine accepts 16-bit linearly-encoded PCM and operates on single-channel audio.

short[] getNextAudioFrame()
{
// .. get audioFrame
return audioFrame;
}
while(true)
{
handle.process(getNextAudioFrame());
}

Once you're done with Picovoice, ensure you release its resources explicitly:

handle.delete();

Custom Wake Word & Context

You can create custom Porcupine wake word and Rhino context models using Picovoice Console

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.


Issue with this doc? Please let us know.