create static method
- String accessKey,
- String keywordPath,
- WakeWordCallback wakeWordCallback,
- String contextPath,
- InferenceCallback inferenceCallback, {
- double porcupineSensitivity = 0.5,
- double rhinoSensitivity = 0.5,
- String? porcupineModelPath,
- String? rhinoModelPath,
- double endpointDurationSec = 1.0,
- bool requireEndpoint = true,
Static creator for initializing Picovoice
accessKey
AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).
keywordPath
Absolute path to Porcupine's keyword model file.
wakeWordCallback
User-defined callback invoked upon detection of the wake phrase.
The callback accepts no input arguments.
contextPath
Absolute path to file containing context parameters. A context represents the set of
expressions(spoken commands), intents, and intent arguments(slots) within a domain of interest.
inferenceCallback
User-defined callback invoked upon completion of intent inference. The callback
accepts a single input argument of type RhinoInference
that is populated with the following items:
(1) isUnderstood
: whether Rhino understood what it heard based on the context
(2) intent
: if isUnderstood, name of intent that were inferred
(3) slots
: if isUnderstood, dictionary of slot keys and values that were inferred
porcupineModelPath
Absolute path to the file containing Porcupine's model parameters.
porcupineSensitivity
Wake word detection sensitivity. It should be a number within 0, 1
. A higher
sensitivity results in fewer misses at the cost of increasing the false alarm rate.
rhinoModelPath
Absolute path to the file containing Rhino's model parameters.
rhinoSensitivity
Inference sensitivity. It should be a number within 0, 1
. A higher sensitivity value
results in fewer misses at the cost of(potentially) increasing the erroneous inference rate.
endpointDurationSec
(Optional) Endpoint duration in seconds. An endpoint is a chunk of silence at the end of an
utterance that marks the end of spoken command. It should be a positive number within 0.5, 5
. A lower endpoint
duration reduces delay and improves responsiveness. A higher endpoint duration assures Rhino doesn't return inference
pre-emptively in case the user pauses before finishing the request.
requireEndpoint
(Optional) If set to true
, Rhino requires an endpoint (a chunk of silence) after the spoken command.
If set to false
, Rhino tries to detect silence, but if it cannot, it still will provide inference regardless. Set
to false
only if operating in an environment with overlapping speech (e.g. people talking in the background).
returns an instance of the Picovoice end-to-end platform.
Implementation
static Future<Picovoice> create(
String accessKey,
String keywordPath,
WakeWordCallback wakeWordCallback,
String contextPath,
InferenceCallback inferenceCallback,
{double porcupineSensitivity = 0.5,
double rhinoSensitivity = 0.5,
String? porcupineModelPath,
String? rhinoModelPath,
double endpointDurationSec = 1.0,
bool requireEndpoint = true}) async {
Porcupine porcupine;
try {
porcupine = await Porcupine.fromKeywordPaths(accessKey, [keywordPath],
modelPath: porcupineModelPath, sensitivities: [porcupineSensitivity]);
} on PorcupineException catch (ex) {
throw mapToPicovoiceException(ex, ex.message);
}
Rhino rhino;
try {
rhino = await Rhino.create(accessKey, contextPath,
modelPath: rhinoModelPath,
sensitivity: rhinoSensitivity,
endpointDurationSec: endpointDurationSec,
requireEndpoint: requireEndpoint);
} on RhinoException catch (ex) {
throw mapToPicovoiceException(ex, ex.message);
}
if (porcupine.frameLength != rhino.frameLength) {
throw PicovoiceInvalidArgumentException(
"Porcupine frame length ${porcupine.frameLength} and Rhino frame length ${rhino.frameLength} are different.");
}
if (porcupine.sampleRate != rhino.sampleRate) {
throw PicovoiceInvalidArgumentException(
"Porcupine sample rate ${porcupine.sampleRate} and Rhino sample rate ${rhino.sampleRate} are different.");
}
return Picovoice._(porcupine, wakeWordCallback, rhino, inferenceCallback);
}