Artyom can talk in Google Chrome too.

This function allows the user to sinthesize any string into sound. This function receives up to 2 arguments, as first the string to sinthesize and as second parameter (optional) an object with the callbacks. It works both in Mobile and Desktop browsers that support the API.

Parameters type Description
text String The string that's meant to be spoken
configuration Object

An object with the 2 available callbacks for this function and the code language if you don't want to use the same language providen in the initialization.

  • onStart: a function triggered when artyom starts to speak.
  • onEnd: a function triggered when artyom stops speaking.
  • lang: force the language for a single utterance object.

artyom.say uses the original speechSynthesis API of Google Chrome but have built-in many work arounds in order to provide a clean and functional text-to-speech method without any character limitation.

  • Artyom remove the limitation of characters in the function of the original API.
  • Artyom guarantee the execution of the callbacks (with the original API those events sometimes decides not to trigger).
  • Artyom simplificates this function for a easily usage.

Example

let artyom = new Artyom();

/**
 * Speak a short string and indicate its callbacks in the console.
 */
artyom.say("A simple demonstration of what i can do.",{
    onStart:function(){
        console.log("The text has been started.");
    },
    onEnd:function(){
        console.log("The text has been finished.");
    }
});

/**
 * Say something
 */
artyom.say("Welcome again");

Force language in a single speech utterance

By default, the say method uses the language providen by the initialization method. You can specify a custom language for a single speech utterance by providing a new property (lang) to the object of the second parameter with the desired code language.

Important

You need to provide an initialization language before forcing the single speech utterance to prevent any error.

let artyom = new Artyom();

// Important, set your default language to prevent any error

artyom.initialize({lang:"en-GB"});


artyom.say("Hello World in English",{
    lang:"en-US",
    onEnd:function(){
        console.log("The text has been finished.");
    }
});

artyom.say("Hola Mundo en español",{
    lang:"es-ES",
    onEnd:function(){
        console.log("El texto ha sido leido");
    }
});

artyom.say("Bonjour tout le monde en français",{
    lang:"fr-FR",
    onEnd:function(){
        console.log("Le texte a été lu");
    }
});

artyom.say("Olá mundo em Português",{
    lang:"pt-PT",
    onEnd:function(){
        console.log("O texto foi lido");
    }
});

artyom.say("Ciao mondo in italiano",{
    lang:"it-IT",
    onEnd:function(){
        console.log("Il testo è stato letto");
    }
});

artyom.say("Using the initialization language here, that means english great britain");

Recommendation for huge blocks of text

If you handle huge amounts of text (more than 20000 characters) and you do it often, you may want to optimize your code. Be aware of clean the garbage collection objects of artyom using artyom.clearGarbageCollection method. Read more about the garbage collection of artyom here and how to clean it here.