Porcupine Wake Word
Flutter API
API Reference for the Porcupine Flutter SDK (pub.dev) .
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
Getter for Porcupine version string.
Porcupine.frameLength
Getter for the number of audio samples per frame required by Porcupine.
Porcupine.sampleRate
Getter for the audio sample rate required by Porcupine.
Porcupine.fromBuiltInKeywords()
Static creator for initializing Porcupine from a selection of built-in keywords.
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? : Path to the file containing model parameters (.pv
). Can be either a path that is relative to the project'sassets
folder or an absolute path to the file on device. If not set it will be set to the default location.sensitivities
List<double>? : sensitivity values for each keyword 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
- a
PorcupineException
if not initialized correctly.
Porcupine.fromKeywordPaths()
Static creator for initializing Porcupine from a list of paths to custom keyword files.
Parameters
accessKey
String : AccessKey obtained from Picovoice Console.keywordPaths
List<String> : A List of paths to keyword files (.ppn
). Can be either paths that are relative to the project'sassets
folder or absolute paths to the files on device.modelPath
String? : Path to the file containing model parameters (.pv
). Can be either a path that is relative to the project'sassets
folder or an absolute path to the file on device. If not set it will be set to the default location.sensitivities
List<double>? : sensitivity values for each keyword 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
PorcupineException
: If not initialized correctly.
Porcupine.process()
Process a frame of audio with the Porcupine Wake Word engine.
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
PorcupineException
: If process fails.
Porcupine.delete()
Frees memory that was allocated for Porcupine.
BuiltInKeyword
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.
PorcupineManager.fromBuiltInKeywords
Static creator for initializing PorcupineManager from a selection of built-in keywords.
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 PorcupinemodelPath
String? : Path to the file containing model parameters (.pv
). Can be either a path that is relative to the project'sassets
folder or an absolute path to the file on device. If not set it will be set to the default location.sensitivities
List<double>? : sensitivities for each keyword 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
PorcupineException
if not initialized correctly.
PorcupineManager.fromKeywordPaths()
Static creator for initializing PorcupineManager from a list of paths to custom keyword files.
Parameters
accessKey
String : AccessKey obtained from Picovoice Console.keywordPaths
List<String> : A List of paths to keyword files (.ppn
). Can be either paths that are relative to the project'sassets
folder or absolute paths to the files on device.wakeWordCallback
WakeWordCallback : A callback that is triggered when one of the given keywords has been detected by Porcupine.modelPath
String? : Path to the file containing model parameters (.pv
). Can be either a path that is relative to the project'sassets
folder or an absolute path to the file on device. If not set it will be set to the default location.sensitivities
List<double>? : sensitivities for each keyword 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
PorcupineException
if not initialized correctly.
PorcupineManager.start()
Opens audio input stream and sends audio frames to Porcupine.
Throws
- a
PvAudioException
if there was a problem starting the audio engine.
PorcupineManager.stop()
Closes audio stream.
PorcupineManager.delete()
Releases Porcupine and audio resources.
WakeWordCallback
Type for function that that is triggered when one of the given keywords has been detected by Porcupine.
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.
Parameters
- error PorcupineException
PorcupineException
Exception thrown if an error occurs within Porcupine Wake Word engine: