flutterPorcupine - Flutter API

API Reference for the Porcupine Flutter SDK (pub.dev) .


Porcupine

class Porcupine { }

Class for the Porcupine Wake Word engine. Porcupine can be initialized either using the High-level PorcupineManager() Class or directly using the creator. Resources should be cleaned when you are done using the delete() function.


Porcupine.version

String get version

Getter for Porcupine version string.


Porcupine.frameLength

int get frameLength

Getter for the number of audio samples per frame required by Porcupine.


Porcupine.sampleRate

int get sampleRate

Getter for the audio sample rate required by Porcupine.


Porcupine.fromBuiltInKeywords()

Static creator for initializing Porcupine from a selection of built-in keywords.

static Future<Porcupine> fromBuiltInKeywords(
String accessKey,
List<BuiltInKeyword> keywords,
{String? modelPath,
List<double>? sensitivities}
)

Parameters

  • accessKey String : AccessKey obtained from Picovoice Console.
  • keywords List<BuiltInKeyword> : A List of (phrases) for detection. The list of available keywords can be retrieved using BuiltInKeyword enum.
  • modelPath String? : A path to the file containing model parameters. If not set it will be set to the default location (.pv).
  • sensitivities List<double>? : sensitivity values 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.

Returns

  • Future<Porcupine> an instance of Porcupine Wake Word engine.

Throws


Porcupine.fromKeywordPaths()

Static creator for initializing Porcupine from a list of paths to custom keyword files.

static Future<Porcupine> fromKeywordPaths(
String accessKey,
List<String> keywordPaths,
{String? modelPath,
List<double>? sensitivities}
)

Parameters

  • accessKey String : AccessKey obtained from Picovoice Console.
  • keywordPaths List<String> : A List of absolute paths to keyword model files (.ppn).
  • modelPath String? : A path to the file containing model parameters. If not set it will be set to the default location (.pv).
  • sensitivities List<double>? : sensitivity values 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.

Returns

  • Future<Porcupine> an instance of the Porcupine Wake Word engine.

Throws


Porcupine.process()

Process a frame of audio with the Porcupine Wake Word engine.

Future<int> process(List<int>? frame)

Parameters

  • frame List<int>? : a frame of audio samples to be assessed by Porcupine. The required audio format is found by calling .sampleRate to get the required sample rate and .frameLength to get the required frame size. Audio must be single-channel and 16-bit linearly-encoded.

Returns

  • int : Index of the detected keyword, or -1 if no detection occurred.

Throws


Porcupine.delete()

Frees memory that was allocated for Porcupine.

Future<void> delete()

BuiltInKeyword

enum BuiltInKeyword {
ALEXA,
AMERICANO,
BLUEBERRY,
BUMBLEBEE,
COMPUTER,
GRAPEFRUIT,
GRASSHOPPER,
HEY_GOOGLE,
HEY_SIRI,
JARVIS,
OK_GOOGLE,
PICOVOICE,
PORCUPINE,
TERMINATOR
}

Enum of available built-in keywords for Porcupine Wake Word engine.


PorcupineManager

Manager for creating an instance of Porcupine. A High-level Flutter binding for Porcupine Wake Word engine that handles recording audio from microphone, processes it in real-time using Porcupine, and notifies the client when any of the given keywords are detected.

class PorcupineManager { }

PorcupineManager.fromBuiltInKeywords

Static creator for initializing PorcupineManager from a selection of built-in keywords.

static Future<PorcupineManager> fromBuiltInKeywords(
String accessKey,
List<BuiltInKeyword> keywords,
WakeWordCallback wakeWordCallback,
{String? modelPath,
List<double>? sensitivities,
ErrorCallback? errorCallback}
)

Parameters

  • accessKey String : AccessKey obtained from Picovoice Console.
  • keywords List<BuiltInKeyword> : A List of (phrases) for detection. The list of available keywords can be retrieved using BuiltInKeyword enum.
  • wakeWordCallback WakeWordCallback : A callback that is triggered when one of the given keywords has been detected by Porcupine
  • modelPath String? : A path to the file containing model parameters. If not set it will be set to the default location (.pv).
  • sensitivities List<double>? : 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.
  • errorCallback ErrorCallback : An optional callback that triggers if Porcupine experiences a problem while processing audio

Returns

  • Future<PorcupineManager> an instance of PorcupineManager.

Throws


PorcupineManager.fromKeywordPaths()

Static creator for initializing PorcupineManager from a list of paths to custom keyword files.

static Future<PorcupineManager> fromKeywordPaths(
String accessKey,
List<String> keywordPaths,
WakeWordCallback wakeWordCallback,
{String? modelPath,
List<double>? sensitivities,
ErrorCallback? errorCallback}
)

Parameters

  • accessKey String : AccessKey obtained from Picovoice Console.
  • keywordPaths List<String> : A List of absolute paths to keyword model files (.ppn).
  • wakeWordCallback WakeWordCallback : A callback that is triggered when one of the given keywords has been detected by Porcupine.
  • modelPath String? : A path to the file containing model parameters. If not set it will be set to the default location (.pv).
  • sensitivities List<double>? : 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.
  • errorCallback ErrorCallback : An optional callback that triggers if Porcupine experiences a problem while processing audio.

Returns

  • Future<PorcupineManager> an instance of PorcupineManager.

Throws


PorcupineManager.start()

Opens audio input stream and sends audio frames to Porcupine.

Future<void> start()

Throws

  • a PvAudioException if there was a problem starting the audio engine.

PorcupineManager.stop()

Closes audio stream.

Future<void> stop()

PorcupineManager.delete()

Releases Porcupine and audio resources.

Future<void> delete()

WakeWordCallback

Type for function that that is triggered when one of the given keywords has been detected by Porcupine.

typedef WakeWordCallback = Function(int keywordIndex);

Parameters

  • keywordIndex int : Index of the detected keyword, or -1 if no detection occurred.

ErrorCallback

Type for the error callback that occurs while processing audio.

typedef ErrorCallback = Function(PorcupineException error);

Parameters


PorcupineException

class PorcupineException implements Exception {}

Exception thrown if an error occurs within Porcupine Wake Word engine:

class PorcupineMemoryException extends PorcupineException { }
class PorcupineIOException extends PorcupineException { }
class PorcupineInvalidArgumentException extends PorcupineException { }
class PorcupineStopIterationException extends PorcupineException { }
class PorcupineKeyException extends PorcupineException { }
class PorcupineInvalidStateException extends PorcupineException { }
class PorcupineRuntimeException extends PorcupineException { }
class PorcupineActivationException extends PorcupineException { }
class PorcupineActivationLimitException extends PorcupineException { }
class PorcupineActivationThrottledException extends PorcupineException { }
class PorcupineActivationRefusedException extends PorcupineException { }


Issue with this doc? Please let us know.