Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Last active April 15, 2021 12:25
Show Gist options
  • Select an option

  • Save jtmuller5/64b564abe116c8982204d0755fd4e517 to your computer and use it in GitHub Desktop.

Select an option

Save jtmuller5/64b564abe116c8982204d0755fd4e517 to your computer and use it in GitHub Desktop.
PorcupineManager porcupineManager;
/// Create an instance of your porcupineManager which will listen for the given wake words
/// Must call start on the manager to actually start listening
void createPorcupineManager() async {
try{
porcupineManager = await PorcupineManager.fromKeywords(
Porcupine.BUILT_IN_KEYWORDS,
wakeWordCallback);
} on PvError catch (err) {
// handle porcupine init error
print('Porcupine error: '+ err.message);
}
}
/// The function that's triggered when the Porcupine instance recognizes a wake word
/// Input is the index of the wake word in the list of those being used
void wakeWordCallback(int word){
print('Wake word index: '+ word.toString());
}
/// Begin listening for a wake word
void listenForWakeWord() async{
try{
await porcupineManager.start();
} on PvAudioException catch (ex) {
// deal with either audio exception
print('PvAudioException: '+ ex.message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment