Now that you have seen how to create a simple “Hello World” recognizer.json file and use it with the provided matcher utility, let’s see how it can be used in the code.
As in the previous tutorials, ensure that you have node and npm installed, create a new directory and initialize npm project there (accepting default values):
Note: if you don’t want to type in all the source code, you don’t have to. This tutorial is available as an npm module. Simply load the module, then copy all the files to your current directory:
As the documentation for vui-ad-hoc-alexa-recognizer states you only need to 2 lines of code to use it. So, let’s see how it’s done.
First, load the module:
Second, load the recognizer.json file:
Third, use it:
“Wait” you say - I am not stupid, that’s 3 lines of code! Well, you are right - the second part (loading the recognizer.json file) is optional.
If this file is placed in the vui-ad-hoc-alexa-recognizer module’s directory and it’s named recognizer.json then vui-ad-hoc-alexa-recognizer will load it by default
and you won’t need to provide it as an argument to matchText() call.
I simply showed you how to load it explicitly, using its path.
So, now let’s add a few niceties, such as parsing out the arguments:
And finally, let’s log the result:
Putting it all together you should have this index.js file:
Now, let’s test it:
And there you have it - a simple script that uses a recognizer file.