Demo entry 6634531

sdfsd

   

Submitted by anonymous on Aug 11, 2017 at 03:17
Language: HTML. Code size: 4.5 kB.

        <script type="text/javascript">
            $(document).ready(function(){
                //initialize mmi class
                var mmiCli = new MMICLient(mmi_im+"GUI", mmi_fusion+"TOUCH");
        
                //handle messages received from the IM
                mmiCli.OnArrive.on(function (data) {
                
                    //Since the mmi is pooling some messages are request to renew the connection, need to be filtered
                    if(data!="RENEW"){
                    
                        //just outputs the content of the emma:interpretation node
                        console.log($(data).find("emma\\:interpretation").first().text().trim());
                        
                        //convert the content into a json object
                        var rec = $.parseJSON( $(data).find("emma\\:interpretation").first().text().trim());
                        
                        //mapping the result into function
                        switch(rec.recognized[1]){
                            //mapping for the touch modality
                            case 'TAP':
                                    click(rec.coordX,rec.coordY);
                                break;
                            //mapping for the face verification
                            case 'VERIFIED':
                                if(rec.recognized[2]=="TRUE"){
                                    sentence ="Bemvindo "+ rec.text;
                                }else{
                                    sentence="Não foi possível identificar.";
                                }
                                speak(sentence);
                                break;
                        }
                        
                        $('#result').html( $.parseJSON( $(data).find("emma\\:interpretation").first().text().trim()).recognized );
                    }
                });

                //Start pooling the interaction manager
                mmiCli.startPoolIM();


                
                //event when clicking on the picture - element must contain the attribute data-idx
                $('.pic').click(function(ev){
                    //set command
                    var command = {"recognized": ["VALIDATE", "PERSON"], "text": ""+$(this).data('idx')+"" };
                    
                    //creating the lifecycle event
                    var lce = new LifeCycleEvent("APP", "FACEVAL", "app-1", "ctx-1").doStartRequest(new EMMA("app-", "display", "command", 1, 0).setValue( JSON.stringify(command) ));
                    
                    //send the event
                    mmiCli.sendToIM(lce);
                });
                
                //REQUEST TO READ A MESSAGE
                function speak(sentence){
                    //SET CONTENT
                    var command = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.w3.org/2001/10/synthesis http://www.w3.org/TR/speech-synthesis/synthesis.xsd\" xml:lang=\"pt-PT\">";
                    command+= "<p> "+sentence+" </p>";
                    command+= "</speak>";
                
                    //create new mmi class, will send the event directly to the IM as an APP generated event
                    var mmiCli2 = new MMICLient(mmi_im+"GUI", mmi_im+"APP");
                    
                    //SEND
                    mmiCli2.sendToIM(new LifeCycleEvent("APP", "TTS", "app-1", "ctx-1").doStartRequest(new EMMA("app-", "display", "command", 1, 0).setValue( JSON.stringify(command) )));
                    
                }
                
                /*
                * CREATE CLICK EVENT
                *
                */
                function click(x, y)
                {
                    var width=$(window)[0].innerWidth, height=$(window)[0].innerHeight;
                    var ev = new MouseEvent('click', {
                        'view': window,
                        'bubbles': true,
                        'cancelable': true,
                        'screenX': x,
                        'screenY': y
                    });

                    var el = document.elementFromPoint(x*width, y*height);

                    el.dispatchEvent(ev);
                }
            });
        </script>

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).