Code Monkey home page Code Monkey logo

Comments (3)

sdkcarlos avatar sdkcarlos commented on May 18, 2024

Hi @ashram78 , if you add an error listener to your code, you'll find that the problem will be identified with "recognition_overlap" (read more about artyom.when here). This error happens when you try to start artyom but it's still active.

To solve it, as you want immediately change of language, you can use a setTimeout to wait 300 ms to be started again.

The speechRecognition cannot be started till the last speechRecognition is finished. However the original API doesn't stop immediately the speechRecognition, therefore you need to use a setTimeout to prevent errors.

/**
 * Note that this commands will work only in english mode .. in other language they will be not so good 
 * recognized.
 */ 
artyom.addCommands({
    // note that if you're in spanish for example
    // the command should be instead : "Iniciar en ingles, Iniciar en alemán" etc...
    indexes:["switch to italian","switch to german",
             "switch to french","switch to spanish",
             "switch to portuguese","switch to dutch",
             "switch to polish","switch to indonesian",
             "switch to english"],
    action: function(i){
        switch(i){
            case 0: stop(); start("it-IT"); break;
            case 1: start("de-IT"); break;
            case 2: start("fr-FR"); break;
            case 3: start("es-ES"); break;
            case 4: start("pt-PT"); break;
            case 5: start("nl-NL"); break;
            case 6: start("pl-PL"); break;
            case 7: start("id-ID"); break;
            case 8: start("en-GB"); break;
        }
    }
});

// on command recognition end
artyom.when("COMMAND_RECOGNITION_END",function(status){
    if(status.code == "continuous_mode_enabled"){
        console.info("Command reconition finalized, restarting because the continuous mode is enabled");
    }
});

function start(language){
    if(!language){
        language = artyom.getLanguage(); 
    }

    var _startArtyom = function(){
        artyom.initialize({
            lang: language,// Start artyom with provided language
            continuous:true,// Continuous mode enabled
            listen:true, // Start recognizing
            debug:true, // Show everything in the console
            speed:1, // talk normally
            executionKeyword: "now" // say "now" at the end of a command to execute it immediately
        });

        console.log("Artyom is listening to your commands");
    };

    // stop artyom if stills active
    artyom.fatality();
    setTimeout(_startArtyom,250);
}

// Catch errors
artyom.when("ERROR",function(data){
    console.error(data);
});

start("en-GB");
// or 
// start("en-US");

from artyom.js.

ashram78 avatar ashram78 commented on May 18, 2024

Thank you Carlos for your great jpb and the quick response. I found the solution with this function:
pausecomp(3000);

function pausecomp(ms) {
ms += new Date().getTime();
while (new Date() < ms){}
}

it's a little hacky, but it works, :-)

from artyom.js.

sdkcarlos avatar sdkcarlos commented on May 18, 2024

@ashram78 , that works however that will block the UI. I recommend to use setTimeout function instead. Thanks for use artyom !

from artyom.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.