Last active
April 15, 2021 12:25
-
-
Save jtmuller5/64b564abe116c8982204d0755fd4e517 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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