let artyom = new Artyom();
// The clear command needs to be executed
// always in the last artyom.say function
artyom.say("Hello , this is a long text 1 .");
artyom.say("Hello , this is a long text 2.");
artyom.say("Hello , this is a long text 3.");
artyom.say("Hello , this is a long text 4.");
artyom.say("Hello , this is a long text 5.");
artyom.say("Hello , this is a long text 6.");
artyom.say("Hello , this is a long text 7.");
artyom.say("Hello , this is a long text. Now i'll clean the garbage collection.",{
onEnd: function(){
var totalObjectsInCollection = artyom.getGarbageCollection().length;
// Clear now that there are no more text to say.
artyom.clearGarbageCollection();
alert("The garbage collection has been cleaned. "+totalObjectsInCollection+" Items found. Now there are " + artyom.getGarbageCollection().length);
}
});
// Remember that SpeechSynthesis is an experimental API
// Therefore, there are many unsolved bugs originally
// @INSTRUCTION 1
// This will add 1 item to the garbage collection
artyom.say("This is a semi long text that will be spoken",{
onEnd: function(){
// If it is executed here , the intruction 2 will be never executed
// Because you just cleaned all the existent SpeechSynthesisObjects
// This is safe only if is executed in the onEnd callback and you're
// sure that no more artyom.say functions will be executed after this instruction
artyom.clearGarbageCollection();
}
});
artyom.say("What's up",{
onEnd: function(){
console.log("You may see this text in the console.");
}
});
artyom.say("I'm trying to do something here. Please shut up your mouth.",{
onEnd: function(){
console.log("Probably this not ...");
}
});
// More instructions ...
artyom.say("Hello, this other text that will be spoken",{
onEnd: function(){
console.log("You may see this text in the console but sometimes don't");
}
});