fromKeywordPaths static method
Static creator for initializing Porcupine from a list of paths to custom keyword files
accessKey
AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).
keywordPaths
A List of absolute paths to keyword model files.
modelPath
is a path to the file containing model parameters. If not set
it will be set to the default location.
sensitivities
sensitivities for each keywords model. A higher sensitivity
reduces miss rate at the cost of potentially higher false alarm rate.
Sensitivity should be a floating-point number within 0 and 1.
Throws a PorcupineException
if not initialized correctly
returns an instance of the wake word engine
Implementation
static Future<Porcupine> fromKeywordPaths(
String accessKey, List<String> keywordPaths,
{String? modelPath, List<double>? sensitivities}) async {
if (modelPath != null) {
modelPath = await _tryExtractFlutterAsset(modelPath);
}
for (var i = 0; i < keywordPaths.length; i++) {
keywordPaths[i] = await _tryExtractFlutterAsset(keywordPaths[i]);
}
try {
Map<String, dynamic> result = Map<String, dynamic>.from(
await _channel.invokeMethod(_NativeFunctions.FROM_KEYWORD_PATHS.name, {
'accessKey': accessKey,
'modelPath': modelPath,
'keywordPaths': keywordPaths,
'sensitivities': sensitivities
}));
return Porcupine._(result['handle'], result['frameLength'],
result['sampleRate'], result['version']);
} on PlatformException catch (error) {
throw porcupineStatusToException(error.code, error.message);
} on Exception catch (error) {
throw porcupineStatusToException("PorcupineException", error.toString());
}
}