Without a command, artyom won't know how to react when you talk. Learn how to add voice commands to artyom.

This method expects as first parameter either an array with commands or a single command. These commands are added to an internal array that contains all the commands of artyom. The commands can be added dinamically and artyom will still process them.

About a command object

A command is a literal object with at less 3 properties:

Property name Type Description
indexes Array An array with all the text identifiers that can trigger the command
smart Boolean In order to process correctly the command, artyom needs to know if the command uses wildcards. In case it does, then set the smart property to true.
action Function A function that will be triggered when the recognized text matches with any of the providen text identifiers within the array of the indexes property. This function, according to the type of command can receive up to 2 parameters (as first parameter the index of the matched command in the indexes array and as second parameter if it's smart the recognized wildcard).

e.g create a command that shows an alert when you say hello:

var command = {
    indexes: ["Hello"],
    action: function(){
        alert("Hello, how are you ?");
    }
};

var artyom = new Artyom();

artyom.addCommands(command);

Add group of commands

You can enter multiple commands for artyom, using an array as input. Every item of the array needs to be a command:

var commands = [
    {
        indexes: ["Hello"],
        action: function(){
            alert("Hello, how are you ?");
        }
    },
    {
        indexes: ["Good night"],
        action: function(){
            alert("Hello, how are you ?");
        }
    },
    {
        indexes: ["Good morning"],
        action: function(){
            alert("Hello, how are you ?");
        }
    }
];

var artyom = new Artyom();

artyom.addCommands(commands);

How to know which command was executed

If you're using a command that reacts to many words, you can retrieve which one was spoken in the action function:

var artyom = new Artyom();

artyom.addCommands({
    indexes: ["Good morning","Good night", "Hello"],
    action: function(i){
        if(i == 2){
            // You said Hello
        }else if(i == 1){
            // You said Good night
        }else if(i == 0){
            // You said Good morning
        }
    }
});

Working with smart commands

A smart command is a voice command, whose contents may have an alterable and obtainable value. You can obtain the alterable value by using the asterisk character (*) within the command and it will be returned as second parameter in the action callback. Note that the smart property of the command needs to be set to true.

For example, you can create a command that will make artyom to repeat everything that you speak after you say "repeat after me":

var artyom = new Artyom();

artyom.addCommands({
    //The smart property of the command needs to be true
    smart:true,
    indexes: ["Repeat after me *"],
    action: function(i, wildcard){
        // Speak alterable value
        artyom.say(wildcard);
    }
});

// Then use the initialize function 
// ..
// And proceed to say "Repeat after me, make a sandwich"
// Then artyom should say "make me a sandwich"

Besides, to make the commands even smarter, and supposing that you know how to use them, you can add regular expressions to your command as long as it's smart. Just add the regular expression as an item of the indexes array:

Important

The regular expression needs to return true when it's tested with the test function.

var artyom = new Artyom();

artyom.addCommands({
    //The smart property of the command needs to be true
    smart:true,
    indexes: [/Good Morning/i, new RegExp("Good Afternoon", "i")],
    action: function(i){
        artyom.say("Hey, are alright? You never say hello.");
    }
});