The initialization of artyom is the key method to create your first voice assistant with Javascript in your web project easily.

The initialization method of artyom is a function that expects an object as first parameter with different configuration properties. This method returns a Promise that is fulfilled in case that the initialization (or configuration changes) were succesfully executed.

Important note

You need to know that artyom needs to be initializated once the window is loaded:

window.onload = function(){
    var artyom = new Artyom();

    artyom.initialize({
        lang:"en-GB",
        debug:true,
        continuous:true,
        listen:true
    }).then(function(){
        console.log("Artyom has been correctly initialized");
        console.log("The following array shouldn't be empty" , artyom.getVoices());
    }).catch(function(){
        console.error("An error occurred during the initialization");
    });
};

Artyom needs to load the voices once the script is loaded in the document, if you initialize the document beforethe windows is loaded then the voice won't be choosen and that will lead to bugs. Interprets this as an insurance policy that will make sure that artyom works correctly in the Window.

Initialization object

The initialization object is required and supports all the following properties:

Name Allowed type Default value what does
listen Boolean false if listen is equal to true the voice recognition will be started otherwise this property can be ignored.
speed Float 1 moderates the speed with which Artyom talks (0 ~ 1)
continuous Boolean false Choose if you want Google Now mode (false) that only listen 1 command and then stops, or a Jarvis (true), that will listen forever (Recognizing all the commands that you give)
debug Boolean false This property allows the developer to be aware of what happens with the recognition of Artyom. Displays all the grammars recognized in the console
volume Float 1 Adjust the volume of the voice of artyom
lang String "en-GB" Set the default language of artyom with this property
mode String "normal"

Till the date, there are 3 available modes, this parameter needs to be providen as a string:

  • normal
  • quick
  • remote

Normal : the commands will be processed if the last recognized text is the final part.

Quick mode : If mode is set to "quick" , artyom will process every word that you say, this provides a quickest recognition, however this mode is not recommended when you use smart commands o long normal commands, but ... why? for example if we have the following commands in the following order: 

"don't add reminder" <- This do something called A
"add reminder"<- This do something called B 

If you say to artyom "add reminder" in quick mode; Artyom will execute the first instruction because he find add reminder in that command although there's other exactly command with "add reminder". This mode can be used if you use very simple and different commands.
Anyway this is just a testing property, pay attention how it works. Quick mode is not recomendable in PRODUCTION Environment of your project

Remote mode : use the remote mode to process your commands in a remote server (or any kind of self-implemented web service). This mode ignores the locally added commands and it will execute the function saved in artyom.remoteProcessorService(function).

executionKeyword String null Set a keyword that allows your command to be executed immediately when you say this word (Useful in noisy environments)
obeyKeyword String null Set a keyword that allows to enable the command recognition automatically if this word (or words) is recognized while artyom is paused by artyom.dontObey.
soundex Boolean false

Enable the soundex algorithm for the command recognition. Sometimes the speech recognition is not 100% accurate, therefore you may want to enable to match a command even when the speech recognition API recognizes something wrong.

For example, if you have a command that reacts to "Open Wallmart" and artyom recognizes "Open Willmar" the command will be not triggered. However, if the soundex option is enabled and artyom recognizes "Open Willmar" the command that reacts to "Open Wallmart" will be executed because the soundex index of these words is the same (O154).

name String null

Provide a name to your assistant. In this way, the assistant will reacts to the commands only when you start a phrase with this name e.g "Jarvis Good Morning".

Start artyom in continuous mode

The continuous mode can be enabled by setting the continuous property at the initialization. To be able to use Artyom.js in a "Jarvis mode", that means, that you can run infinity number of voice commands and Artyom will not stop listening to you, you will need a https connection for your project, otherwise the microphone permission dialog will appear repeteadly every time that artyom restarts itself.

var artyom = new Artyom();

artyom.initialize({
    lang:"en-GB",
    //Listen Forever
    continuous:true,
    // Log everything in the console
    debug:true,
    // Initialize artyom !
    listen:true
});

Start artyom in single command mode

The single command mode is perfect for those developers that want that the user clicks a button and then only 1 command will be processed, after the execution of the command artyom will stop automatically. 

var artyom = new Artyom();

artyom.initialize({
    lang:"en-GB",
    // Process 1 command, if nothing recognized then it will stop
    continuous:false,
    // Log everything in the console
    debug:true,
    // Initialize artyom !
    listen:true
});

Check for initialization result

You can verify if the initialization of artyom was succesfully executed by accesing the then and catch properties of the returned Promise of the method. This comes in handy when you want to execute some code only after artyom is listening:

var artyom = new Artyom();

artyom.initialize({
    lang:"en-GB",
    continuous:true,
    debug:true,
    listen:true
}).then(() => {
    artyom.say("Artyom succesfully initialized");
}).catch((err) => {
    artyom.say("Artyom couldn't be initialized, please check the console for errors");
    console.log(err);
});

Using an execution keyword

The execution keyword allow you to execute the voice command immediately after you say this keyword. This option comes in handy in noisy environments where a lot of people talk in the background e.g you want to execute the "stop the music" command however if someone talks, that will be recognized and the command may not be execute due to the recognized text. However with the executionKeyword enabled with a value of "and do it now" and you say "stop the music and do it now" then artyom will execute the command immediately without expecting more voice input:

var artyom = new Artyom();

artyom.addCommands({
    indexes:["Stop the music","Shut up the music"],
    action:function(i){
        var musicEnvironment = new ImaginaryMusicEnvironment();
        musicEnvironment.stop();
    }
});

artyom.initialize({
    executionKeyword:"and do it now",
    lang:"en-GB",
    debug:true, //Show what recognizes in the Console
    listen:true //Start listening after this 
});

// Now imagine that you are in a noisy city and you say "Stop the music".
// Without a execution keyword artyom will take time to accomplish that task because there
// are more persons talking and it hear everything. But with an execution keyword :
// Say "Stop the music and do it now" <- Will stop the music inmmediately

Using the obeyKeyword

The obeyKeyword allow you to enable the command processing of artyom if it was disabled by the artyom.dontObey method. Although the Speech Recognition object of Google Chrome doesn't offer a Pause feature, artyom does, with the artyom.dontObey method. The voice recognition will still active, however not any command will be processed while the internal obey property is set to false. 

This property exists unique and exclusively to allow the creation of a workflow like e.g "don't process anything" then this command will trigger the artyom.dontObey function and although artyom still active, it doesn't execute any command, then you can pronounce the providen keyword of the obeyKeyword property at the initialization like "listen to me again" and artyom can process commands again:

var artyom = new Artyom();

artyom.addCommands([
    {
        indexes:["Stop listening"],
        action:function(i){
            artyom.dontObey();
            console.log("Artyom isn't obeying anymore");
        }
    },
    {
        indexes:["Say hello"],
        action:function(i){
            artyom.say("Hello");
        }
    }
]);

artyom.initialize({
    lang:"en-GB",
    obeyKeyword: "listen to me again",
    debug:true, //Show what recognizes in the Console
    listen:true //Start listening after this 
});

// Then you say : "stop listening"
// Then try to say : "Say hello" and that should be not executed :(
// Then say : "listen to me again"
// And finally say again: "Say hello" and artyom should say hello !