コード例 #1
0
        void CloseHandGesture_OnGestureDetected(string gesture)
        {
            string json_msg = "{ \"recognized\": [";

            json_msg += "\"" + "right-hand" + "\", ";
            json_msg += "\"" + "gesto" + "\":\"" + gesture + "\"";
            json_msg.Substring(0, json_msg.Length - 2);
            json_msg += "] }";

            var exNot = lce.ExtensionNotification("", "", 0.0f, json_msg);

            Console.WriteLine(exNot);
            mmic.Send(exNot);
        }
コード例 #2
0
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            if (e.Result.Confidence < minimum_confidence_threshold)
            {
                return;
            }

            //SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SHAPE","COLOR"]}
            string json = "{ \"recognized\": [";

            foreach (var resultSemantic in e.Result.Semantics)
            {
                json += "\"" + resultSemantic.Value.Value + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "] }";

            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            mmic.Send(exNot);
        }
コード例 #3
0
ファイル: SpeechMod.cs プロジェクト: NunoArmas/IM
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            if (e.Result.Confidence >= 0.6)
            {
                string[] tags = getTags(e.Result.Semantics);
                string   msg  = needsConfirmation(tags);

                if (msg != null)
                {
                    //Send data to server
                    if (!msg.Equals(""))
                    {
                        Console.WriteLine("Sending: " + msg);

                        var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, msg);
                        mmic.Send(exNot);
                    }
                }
            }
        }
コード例 #4
0
        public void sendMessage(String message)
        {
            string json = "{ \"recognized\": [";

            json += "\"" + message + "\", ";
            json  = json.Substring(0, json.Length - 2);
            json += "] }";

            lastResult      = _calc.makeCalculation(expression);
            TextRegion.Text = lastResult.ToString();
            expression      = lastResult.ToString();
            _calc.resetValues();
            gotResult = true;

            if (TextRegion.Text.Contains(","))
            {
                gotResult  = false;
                lastResult = 0;
                expression = "";
            }

            var exNot = lce.ExtensionNotification("", "", 1, json);

            mmic.Send(exNot);
        }
コード例 #5
0
        private void SendMsg_Tts(string message, string type)
        {
            string json  = "{\"action\":\"" + type + "\",\"text_to_speak\":\"" + message + "\"}";
            var    exNot = lce_speechMod.ExtensionNotification("", "", 0, json);

            mmic_speechMod.Send(exNot);
        }
コード例 #6
0
        private void SRE_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            //SEND JSON MESSAGE
            string json = "{";

            foreach (var resultSemantic in e.Result.Semantics)
            {
                json += "\"" + resultSemantic.Key + "\":\"" + resultSemantic.Value.Value + "\", ";
            }
            json.Substring(0, json.Length - 2);
            json += " }";

            var exNot = LCE.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            if (e.Result.Confidence > 0.85)
            {
                Console.WriteLine(exNot);
                MMIC.Send(exNot);
            }
        }
コード例 #7
0
        private void SendCommand(string command)
        {
            //SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SEARCH","FLIGHT"]}
            string json  = "{ \"recognized\":[\"" + command + "\",\"\"] }";
            var    exNot = lce.ExtensionNotification("", "", 100, json);

            mmic.Send(exNot);
        }
コード例 #8
0
        public void SendCommand(String command)
        {
            //SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SHAPE","COLOR"]}
            string json = "{ \"recognized\":[\"" + command + "\"] }";

            var exNot = lce.ExtensionNotification("", "", 100, json);

            mmic.Send(exNot);
        }
コード例 #9
0
        private void sendMessage(string gesture)
        {
            string json = "{ \"recognized\": [";

            json += "\"" + gesture + "\", ";
            json  = json.Substring(0, json.Length - 2);
            json += "] }";

            var exNot = lce.ExtensionNotification("", "", 1, json);

            mmic.Send(exNot);
        }
コード例 #10
0
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            /*foreach (var resultSemantic in e.Result.Semantics)
             *  Console.WriteLine(resultSemantic.Key+":"+resultSemantic.Value.Value);*/

            string json  = "{ \"recognized\": [";
            bool   first = true;

            if (e.Result.Confidence <= 0.30)
            {
                return;
            }

            foreach (var resultSemantic in e.Result.Semantics)
            {
                if (!resultSemantic.Value.Value.ToString().Equals(""))
                {
                    json  = AddJsonTag(json, resultSemantic.Key, resultSemantic.Value.Value.ToString(), first);
                    first = false;
                }
            }
            if (first)
            {
                json = "{ ";
            }


            if (e.Result.Confidence > 0.30 && e.Result.Confidence <= 0.45)
            {
                json = AddJsonTag(json, "confidence", "low confidence", false);
            }
            else if (e.Result.Confidence > 0.45 && e.Result.Confidence < 0.8)
            {
                json = AddJsonTag(json, "confidence", "explicit confirmation", false);
            }
            else if (e.Result.Confidence >= 0.8)
            {
                json = AddJsonTag(json, "confidence", "implicit confirmation", false);
            }
            json  = AddJsonTag(json, "modality", "speech", false);
            json  = json.Substring(0, json.Length - 2);
            json += "}";
            Console.WriteLine(json);
            //Console.WriteLine("--------"+e.Result.Semantics["action"].Value+"-------");
            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            mmic.Send(exNot);
        }
コード例 #11
0
ファイル: SecondMod.cs プロジェクト: ALAMoreira/IMassignment4
        //  NEW
        //  A TEIXEIRA , 16 MAY 2018

        internal void sendToFusion(string value)
        {
            //SEND
            string json = "{ \"recognized\": [";
            //foreach (var resultSemantic in e.Result.Semantics)

            String key = "color";

            json += "\"" + key + "\",\"" + value + "\", ";

            json = json.Substring(0, json.Length - 2);


            json += " ] }";

            //  start time, end time, confidence, json  TO BE COMPLETED
            var exNot = lce.ExtensionNotification("-1", "-1", 1.0f, json);


            mmic.Send(exNot);
        }
コード例 #12
0
        private void GJson()
        {
            string gesture = "{";

            if (reset == false)
            {
                if (this.gestureResultView.Headphones < 0.2 &&
                    this.gestureResultView.Hands_air < 0.3 &&
                    this.gestureResultView.Kill < 0.2 &&
                    this.gestureResultView.Play_Pause < 0.2 &&
                    this.gestureResultView.Swipe_Left < 0.2 &&
                    this.gestureResultView.Swipe_Right < 0.2 &&
                    this.gestureResultView.Jarbas_Init < 0.2)
                {
                    reset = true;
                }
            }
            else
            {
                if (this.gestureResultView.Headphones > 0.5 ||
                    this.gestureResultView.Hands_air > 0.7 ||
                    this.gestureResultView.Kill > 0.5 ||
                    this.gestureResultView.Play_Pause > 0.5 ||
                    this.gestureResultView.Swipe_Left > 0.5 ||
                    this.gestureResultView.Swipe_Right > 0.4 ||
                    this.gestureResultView.Jarbas_Init > 0.5)
                {
                    gesture += "\"" + "Kill" + "\":\"" + this.gestureResultView.Kill + "\", ";
                    gesture += "\"" + "Hands_air" + "\":\"" + this.gestureResultView.Hands_air + "\", ";
                    gesture += "\"" + "Headphones" + "\":\"" + this.gestureResultView.Headphones + "\", ";
                    gesture += "\"" + "Swipe_Right" + "\":\"" + this.gestureResultView.Swipe_Right + "\", ";
                    gesture += "\"" + "Swipe_Left" + "\":\"" + this.gestureResultView.Swipe_Left + "\", ";
                    gesture += "\"" + "Play_Pause" + "\":\"" + this.gestureResultView.Play_Pause + "\", ";
                    gesture += "\"" + "Jarbas_init" + "\":\"" + this.gestureResultView.Jarbas_Init + "\", ";

                    gesture.Substring(0, gesture.Length - 2);
                    gesture += "}";
                    var exNot = lce.ExtensionNotification("", "", 0.0f, gesture);
                    Console.WriteLine("Kill" + this.gestureResultView.Kill);
                    Console.WriteLine("Play_Pause" + this.gestureResultView.Play_Pause);
                    Console.WriteLine("Headphones" + this.gestureResultView.Headphones);
                    Console.WriteLine("Hands_air" + this.gestureResultView.Hands_air);
                    Console.WriteLine("Swipe_Left" + this.gestureResultView.Swipe_Left);
                    Console.WriteLine("Swipe_right" + this.gestureResultView.Swipe_Right);
                    Console.WriteLine("Jarbas_init" + this.gestureResultView.Jarbas_Init);
                    mmic.Send(exNot);
                    reset = false;
                }
            }
        }
コード例 #13
0
ファイル: GestureMod.cs プロジェクト: pedroyzkrak/IM_Gestures
        public void GestureRecognized(String action, float confidence)
        {
            //SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SHAPE","COLOR"]}
            string json = "{ \"recognized\": [";

            json += "\"" + action + "\", ";
            json  = json.Substring(0, json.Length - 2);
            json += "] }";
            Console.WriteLine(json);

            var exNot = lce.ExtensionNotification("", "", confidence, json);

            mmic.Send(exNot);
        }
コード例 #14
0
        // Send JSON message indicating the parameters in use
        private void sendMessage(string gesture, double confidence)
        {
            string json = "{ \"recognized\": [";

            json += "\"" + gesture + "\", ";
            // Just using the first two comands. The rest is EMP
            for (int i = 1; i < 8; i++)
            {
                json += "\"" + "EMP" + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "] }";
            var exNot = lce.ExtensionNotification("", "", 1, json);

            mmic.Send(exNot);
        }
コード例 #15
0
        public void gestureSelection(string selection)
        {
            if (!serverPipe.IsSpeakRunning)
            {
                StringBuilder json = new StringBuilder("{ \"type\": \"NORMAL\",\"confidence\": \"GOOD\",\"recognized\": [" + "\"" + selection + "\"");
                switch (selection)
                {
                case "CANTEENS":
                    json.Append(",\"TYPE5\" ] }");
                    break;

                case "SAS":
                    string subtype = "SUBTYPE1";
                    string type    = "TYPE1";
                    json.Append(",\"" + type + "\"," + "\"" + subtype + "\"" + "] }");
                    break;

                case "SAC":
                    json.Append(",\"TYPE1\" ] }");
                    break;

                case "NEWS":
                    json.Append(",\"TYPE1\" ] }");
                    break;

                case "WEATHER":
                    json.Append(",\"TYPE1\",\"tomorrow\",\"tomorrow\",\"\" ] }");
                    break;

                case "HELP":
                    json.Append(" ] }");
                    break;
                }

                //gui color change
                mainWindow.resetDefaultColor();
                serverPipe.IsSpeakRunning = true; //manual change so dont allow kinect change to orange between frames
                mainWindow.changeColorTiles(selection, Brushes.Green);


                Console.WriteLine(json.ToString());
                var exNot = lce.ExtensionNotification(0 + "", 10 + "", 0, json.ToString());
                mmic.Send(exNot);
            }
        }
コード例 #16
0
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            // SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SHAPE","COLOR"]}
            string json = "{ \"recognized\": [";

            foreach (var resultSemantic in e.Result.Semantics)
            {
                json += "\"" + resultSemantic.Value.Value + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "] }";

            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            if (e.Result.Confidence > 0.75)
            {
                Console.WriteLine(exNot);
                mmic.Send(exNot);
            }
            else
            {
                Console.WriteLine("Confiança do comando de voz inferior a 85%");
                Random random = new Random();
                int    i      = random.Next(0, 10);
                if (i <= 3)
                {
                    tts.Speak("Não percebi o comando. Repita se faz favor.");
                }
                else if (i <= 4 && i >= 7)
                {
                    tts.Speak("Importa-se de repetir o comando se faz favor?");
                }
                else
                {
                    tts.Speak("Repita se faz favor o comando, não percebi...");
                }
            }
        }
コード例 #17
0
ファイル: SpeechMod.cs プロジェクト: tiagohpf/im-2018-assign4
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            string json = "{ \"recognized\": [";

            foreach (var resultSemantic in e.Result.Semantics)
            {
                json += "\"" + resultSemantic.Value.Value + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "] }";
            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            mmic.Send(exNot);
        }
コード例 #18
0
        private void SendCommand(int position)
        {
            if (position == 0)
            {
                typeSelected        = "FLIGHT";
                destinationSelected = "PARIS";
            }
            if (position == 1)
            {
                typeSelected        = "FLIGHT";
                destinationSelected = "ROME";
            }
            if (position == 2)
            {
                typeSelected        = "FLIGHT";
                destinationSelected = "LONDON";
            }
            if (position == 3)
            {
                typeSelected        = "HOTEL";
                destinationSelected = "PARIS";
            }
            if (position == 4)
            {
                typeSelected        = "HOTEL";
                destinationSelected = "ROME";
            }
            if (position == 5)
            {
                typeSelected        = "HOTEL";
                destinationSelected = "LONDON";
            }

            //SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["FLIGHT","PARIS"]}
            string json = "{ \"recognized\":[\"" + typeSelected + "\",\"" + destinationSelected + "\"] }";

            var exNot = lce.ExtensionNotification("", "", 100, json);

            mmic.Send(exNot);
        }
コード例 #19
0
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            if (e.Result.Confidence < 0.5)
            {
                t.Speak("Desculpe não percebi. Repita por favor.");
                //System.Threading.Thread.Sleep(2000);
            }
            else
            {
                string json = "{\n";
                foreach (var resultSemantic in e.Result.Semantics)
                {
                    foreach (var key in resultSemantic.Value)
                    {
                        json += "\"" + key.Key + "\": " + "\"" + key.Value.Value + "\",\n ";
                    }
                }
                json += "\"" + "mode" + "\": " + "\"" + this.mode + "\",\n ";
                json  = json.Substring(0, json.Length - 1);
                json += "\n}";

                dynamic tojson = JsonConvert.DeserializeObject(json);


                if (tojson.wake != null)
                {
                    wake = true;
                    // Get my atual location in the beggining
                    api.setLocation();
                }
                String name = "";
                if (wake)
                {
                    if (json.Split(new string[] { "action" }, StringSplitOptions.None).Length > 3)
                    {
                        t.Speak("Utilize só um comando de cada vez.");
                    }
                    else
                    {
                        //App.Current.Dispatcher.Invoke(() => {
                        if (tojson.action != null)
                        {
                            switch ((string)tojson.action.ToString())
                            {
                            case "SEARCH":

                                // Get information about a location or service
                                if ((string)tojson.info != null)
                                {
                                    if ((string)tojson.service != null)
                                    {
                                        t.Speak(api.GetInfo((string)tojson.ToString(), (string)tojson.service.ToString(), null, (string)tojson.info));
                                        Console.WriteLine(api.GetInfo((string)tojson.ToString(), (string)tojson.service.ToString(), null, (string)tojson.info));
                                    }
                                    else if ((string)tojson.local != null)
                                    {
                                        t.Speak(api.GetInfo((string)tojson.ToString(), null, (string)tojson.local.ToString(), (string)tojson.info));
                                        Console.WriteLine(api.GetInfo((string)tojson.ToString(), null, (string)tojson.local.ToString(), (string)tojson.info));
                                    }
                                }

                                // Search by restaurant, bar, coffee shop, police, amoung others
                                else if ((string)tojson.service != null)
                                {
                                    // When the input contains an location like, Aveiro, Coimbra, Lisbon
                                    if ((string)tojson.location != null)
                                    {
                                        // Get the closest input for that location (restaurant, coffee shop, etc)
                                        if ((string)tojson.nearby != null)
                                        {          // If there's no one in one km it return a message
                                            name = api.GetClosestPlace((string)tojson.ToString(), (string)tojson.service.ToString(), null, (string)tojson.location.ToString());
                                            t.Speak(api.speak(name));
                                            Console.WriteLine(api.speak(name));
                                        }
                                        // Number of inputs(restaurants, coffee, etc) in a radious of 5km from that location
                                        else
                                        {
                                            t.Speak(api.GetClosestPlaceCounter((string)tojson.ToString(), (string)tojson.service.ToString(), null, (string)tojson.location.ToString()));
                                            t.Speak(api.speak(name));
                                            Console.WriteLine(api.speak(name));
                                        }
                                    }         // When the input DOESN'T contain an location (use coordinates)
                                    else
                                    {
                                        // Get the closest input using coordinates (restaurant, coffee shop, etc)
                                        if ((string)tojson.nearby != null)
                                        {
                                            name = (api.GetClosestPlace((string)tojson.ToString(), (string)tojson.service.ToString(), null, null));
                                            t.Speak(api.speak(name));
                                            Console.WriteLine(api.speak(name));
                                        }
                                        // Number of inputs (restaurants, coffee, etc) in a radious of 5km from that coordinates
                                        else
                                        {
                                            t.Speak(api.GetClosestPlaceCounter((string)tojson.ToString(), (string)tojson.service.ToString(), null, null));
                                        }
                                        Console.WriteLine(api.GetClosestPlaceCounter((string)tojson.ToString(), (string)tojson.service.ToString(), null, null));
                                    }
                                    if (name != "")
                                    {
                                        tojson.service = name;
                                        json           = JsonConvert.SerializeObject(tojson);
                                    }
                                }

                                // Search by "store" like McDonald's, Forum, Altice, amoung others
                                else if ((string)tojson.local != null)
                                {
                                    // When the input contains an location like, Aveiro, Coimbra, Lisbon
                                    if ((string)tojson.location != null)
                                    {
                                        // Get the closest input for that location (McDonald's, Forum, etc)
                                        if ((string)tojson.nearby != null)
                                        {
                                            name = (api.GetClosestPlace((string)tojson.ToString(), null, (string)tojson.local.ToString(), (string)tojson.location.ToString()));
                                            t.Speak(api.speak(name));
                                            Console.WriteLine(api.speak(name));
                                        }
                                        // Number of inputs(McDonald's, Forum, etc) in a radious of 5km from that location
                                        else
                                        {
                                            t.Speak(api.GetClosestPlaceCounter((string)tojson.ToString(), null, (string)tojson.local.ToString(), (string)tojson.location.ToString()));
                                            Console.WriteLine(api.GetClosestPlaceCounter((string)tojson.ToString(), null, (string)tojson.local.ToString(), (string)tojson.location.ToString()));
                                        }
                                    }         // When the input DOESN'T contain an location (use coordinates)
                                    else
                                    {
                                        // Get the closest input using coordinates (McDonald's, Forum, etc)
                                        if ((string)tojson.nearby != null)
                                        {
                                            name = (api.GetClosestPlace((string)tojson.ToString(), null, (string)tojson.local.ToString(), null));
                                            t.Speak(api.speak(name));
                                            Console.WriteLine(api.speak(name));
                                        }

                                        // Number of inputs (McDonald's, Forum, etc) in a radious of 5km from that coordinates
                                        else
                                        {
                                            t.Speak(api.GetClosestPlaceCounter((string)tojson.ToString(), null, (string)tojson.local.ToString(), null));
                                        }
                                        Console.WriteLine(api.GetClosestPlaceCounter((string)tojson.ToString(), null, (string)tojson.local.ToString(), null));
                                    }
                                    if (name != "")
                                    {
                                        tojson.local = name;
                                        json         = JsonConvert.SerializeObject(tojson);
                                    }
                                }

                                break;

                            case "MORE":            // More zoom

                                if ((string)tojson.zoom != null)
                                {
                                    t.Speak("Aumentei zoom");
                                }
                                Console.WriteLine("Aumentei o zoom");
                                break;

                            case "LESS":            // Less zoom

                                if ((string)tojson.zoom != null)
                                {
                                    t.Speak("Diminui zoom");
                                }
                                Console.WriteLine("Diminui o zoom");
                                break;

                            case "CHANGE":

                                if ((string)tojson.view != null)
                                {
                                    t.Speak("Modo de visualização alterado com sucesso");
                                }

                                else if (tojson.subaction == "TRANSPORTE")
                                {
                                    if ((string)tojson.transport != null)
                                    {
                                        // Default: carro; Others: pé, bicicleta, metro, comboio, transportes publicos
                                        mode = (string)tojson.transport.ToString();
                                        t.Speak(string.Format("Modo de transporte alterado para {0}", api.Translate(mode)));
                                        Console.WriteLine("Modo de transporte alterado para {0}", api.Translate(mode));
                                    }
                                    else
                                    {
                                        t.Speak("Peço desculpa, não entendi o meio de transporte.");
                                    }
                                }
                                else
                                {
                                    t.Speak("Peço desculpa, não entendi o que pertende alterar.");
                                }

                                break;

                            case "DIRECTIONS":

                                if ((string)tojson.service != null)
                                {
                                    // Restaurante, Bar, Cafe, Padaria, Hotel, PSP, CGD
                                    if ((string)tojson.location != null)
                                    {
                                        t.Speak("Foram pedidas direcções para " + (string)tojson.service.ToString() + " em " + (string)tojson.location.ToString());
                                        Console.WriteLine("Foram pedidas direcções para " + (string)tojson.service.ToString() + " em " + (string)tojson.location.ToString());
                                    }
                                    else
                                    {
                                        t.Speak("Foram pedidas direcções para " + (string)tojson.service.ToString());
                                        Console.WriteLine("Foram pedidas direcções para " + (string)tojson.service.ToString());
                                    }
                                }
                                else if ((string)tojson.local != null)
                                {
                                    // McDonalds, Continente, Forum, Glicinias, Altice, Ria
                                    if ((string)tojson.location != null)
                                    {
                                        t.Speak("Foram pedidas direcções para " + (string)tojson.local.ToString() + " em " + (string)tojson.location.ToString());
                                        Console.WriteLine("Foram pedidas direcções para " + (string)tojson.local.ToString() + " em " + (string)tojson.location.ToString());
                                    }
                                    else
                                    {
                                        t.Speak("Foram pedidas direcções para " + (string)tojson.local.ToString());
                                        Console.WriteLine("Foram pedidas direcções para " + (string)tojson.local.ToString());
                                    }
                                }
                                break;

                            case "SHUTDOWN":

                                System.Environment.Exit(1);
                                break;
                            }
                        }
                        else
                        {
                            //sre.RecognizeAsyncStop();
                            t.Speak("Olá! Como posso ajudar?");
                            Console.WriteLine("Olá! Como posso ajudar?");
                        }
                        //});
                        var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);
                        //Console.WriteLine((string)exNot.ToString());
                        mmic.Send(exNot);
                    }
                }
            }
        }
コード例 #20
0
        private void SendDetectedGesture(string gesture, double confidence)
        {
            MainWindow.main.ChangeDetectedGesture = gesture + " detected";
            string json = "{\"recognized\": [\"action\", ";

            switch (gesture)
            {
            case deafGestureName:
                json += "\"DEAF_USER\"]";
                break;

            case muteGestureName:
                json += "\"MUTE_USER\"]";
                break;

            case deleteGestureName:
                json += "\"DELETE_LAST_MESSAGE\"]";
                break;

            case kickGestureName:
                json += "\"REMOVE_USER\"]";
                break;

            case banGestureName:
                json += "\"BAN_USER\"]";
                break;

            case selfDeafGestureName:
                json += "\"SELF_DEAF\"]";
                break;

            case selfMuteGestureName:
                json += "\"SELF_MUTE\"]";
                break;

            default:
                Console.WriteLine("Invalid action");
                break;
            }

            if (channelSelected != null)
            {
                json  = json.Substring(0, json.Length - 1);
                json += ", \"channelName\", \"" + channelSelected + "\"]";
            }
            if (userSelected != null)
            {
                json  = json.Substring(0, json.Length - 1);
                json += ", \"userName\", \"" + userSelected + "\"]";
            }
            if (guildSelected != null)
            {
                json  = json.Substring(0, json.Length - 1);
                json += ", \"guildName\", \"" + guildSelected + "\"]";
            }

            json += ", \"confidence\":\"implicit confirmation\", \"modality\":\"gesture\"}";
            Console.WriteLine(json);
            var exNot = lce.ExtensionNotification("", "", (float)confidence, json);

            mmic.Send(exNot);
            if (channelSelected != null)
            {
                MainWindow.main.ChangeColorBTNChannelSelected(channelSelected);
            }
            if (userSelected != null)
            {
                MainWindow.main.ChangeColorBTNUserSelected(userSelected);
            }

            channelSelected = null;
            userSelected    = null;
        }
コード例 #21
0
        private bool processRequest(SpeechRecognizedEventArgs e)
        {
            if (eventQueue.Count == 0 || (eventQueue.Count != 0 && e.Result.Semantics.ToArray()[0].Value.Value.Equals("Confirm")))
            {
                switch (e.Result.Semantics.ToArray()[0].Value.Value)
                {
                // TODO: Decide wether to send (feeback and request)
                case "cidades":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar a cidade  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura da cidade " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Comidas":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar por   " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura de  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Tipodeestabelecimento":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar por   " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura de  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Limpar":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis limpar os filtros ?");
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a limpar os filtros ");
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Confirm":
                    if (e.Result.Semantics.ToArray()[1].Value.Value.ToString().Equals("Sim"))
                    {
                        try
                        {
                            e = eventQueue.Dequeue();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }


                        t.Speak("Estou a efectuar a acção pedida!!");

                        string json = "{ \"recognized\": [";
                        foreach (var resultSemantic in e.Result.Semantics)
                        {
                            json += "\"" + resultSemantic.Value.Value + "\", ";
                        }
                        json  = json.Substring(0, json.Length - 2);
                        json += "] }";

                        var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

                        mmic.Send(exNot);
                        return(false);
                    }
                    else
                    {
                        t.Speak("Pesquisa cancelada, por fovor qual é a proxima ação");
                        try
                        {
                            e = eventQueue.Dequeue();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                        return(false);
                    }

                case "Restaurantes":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar o restaurante  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a abrir o restaurante " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "TipodeReserva":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar o tipo de reserva  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura do tipo de reserva " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Cozinhasepratos":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar o tipo de comida  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura do tipo de comida " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Preco":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar o preço " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura do preço " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Caracteristicasdorestaurante":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar restaurantes com a característica  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura de restaurantes com a característica " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Bonspara":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar restaurantes bons para  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procurar restaurantes bons para " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Refeicoes":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar a refeição  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou à procura da refeição " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Restricoesalimentares":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis procurar a restrição alimentar  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a procura da restrição alimentar " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }

                case "Mais":
                    if (e.Result.Confidence < 0.20)
                    {
                        t.Speak("Não consegui entender, por favor repita");
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.20 && e.Result.Confidence < 0.60)
                    {
                        // obtem informação se é mesmo isto
                        Console.WriteLine(e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        t.Speak("Não consegui entender, Será que quis ver mais sobre  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        eventQueue.Enqueue(e);
                        return(false);
                    }
                    else if (e.Result.Confidence >= 0.60 && e.Result.Confidence < 0.80)
                    {
                        // procura e obtem info
                        t.Speak("Estou a ver mais " + e.Result.Semantics.ToArray()[1].Value.Value.ToString());
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            else
            {
                e = eventQueue.Peek();
                switch (e.Result.Semantics.ToArray()[0].Value.Value)
                {
                // TODO: Decide wether to send (feeback and request)
                case "cidades":
                    t.Speak("Por favor confirme que quer pesquisar a cidade " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Comidas":
                    t.Speak("Por favor confirme que quer pesquisar pelo tipo de comida " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Tipodeestabelecimento":
                    t.Speak("Por favor confirme que quer pesquisar pelo tipo de estabelecimento " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Limpar":
                    t.Speak("Por favor confirme que quer lempar todos os filtros. Responda sim ou não");
                    break;

                case "Restaurantes":
                    t.Speak("Por favor confirme que quer pesquisar pelo Restaurante " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "TipodeReserva":
                    t.Speak("Por favor confirme que quer pesquisar pelo tipo de reserva " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Cozinhasepratos":
                    t.Speak("Por favor confirme que quer pesquisar pelo tipo de cozinha " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Preco":
                    t.Speak("Por favor confirme que quer pesquisar pelo tipo de preço " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Caracteristicasdorestaurante":
                    t.Speak("Por favor confirme que quer pesquisar pela seguinte caracteristica do restaurante " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Bonspara":
                    t.Speak("Por favor confirme se o restaurante que quer é bom para " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Refeicoes":
                    t.Speak("A refeição que prefere é " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Restricoesalimentares":
                    t.Speak("A sua restrição é  " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;

                case "Mais":
                    t.Speak("Quer ver mais informação sobre " + e.Result.Semantics.ToArray()[1].Value.Value.ToString() + " . Responda sim ou não");
                    break;
                }
            }

            return(false);
        }
コード例 #22
0
ファイル: SpeechMod.cs プロジェクト: diogo-marques/im_gc_2020
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });
            String exNot;

            //SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SHAPE","COLOR"]}
            if (e.Result.Confidence < 0.65)
            {
                t.Speak("Repita a frase, por favor.");
            }
            else
            {
                string json = "{ \"recognized\": [";
                foreach (var resultSemantic in e.Result.Semantics)
                {
                    json += "\"" + resultSemantic.Value.Value + "\", ";
                }
                json  = json.Substring(0, json.Length - 2);
                json += "] }";

                Console.WriteLine(json);
                if (confirmationFlag)
                {
                    if (e.Result.Semantics.First().Value.Value.Equals("YES"))
                    {
                        exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, prev_json);
                        mmic.Send(exNot);
                        confirmationFlag = false;
                    }
                    else if (e.Result.Semantics.First().Value.Value.Equals("NO"))
                    {
                        confirmationFlag = false;
                    }
                }
                else
                {
                    if (e.Result.Semantics.First().Value.Value.Equals("THANKS"))
                    {
                        t.Speak("De nada, foi um prazer poder ajudar.");
                    }
                    else if (e.Result.Semantics.First().Value.Value.Equals("CREATE_EVENT"))
                    {
                        confirmationFlag = true;
                        prev_json        = json;
                        if (e.Result.Semantics.ElementAt(2).Value.Value.Equals("TOMORROW"))
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende marcar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " amanhã às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende marcar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " amanhã às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                        else if (e.Result.Semantics.ElementAt(2).Value.Value.Equals("TODAY"))
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende marcar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " hoje às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende marcar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " hoje às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                        else
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende marcar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " no dia " + sToDateS(e.Result.Semantics.ElementAt(2).Value.Value.ToString()) + " às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende marcar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " no dia " + sToDateS(e.Result.Semantics.ElementAt(2).Value.Value.ToString()) + " às " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                    }
                    else if (e.Result.Semantics.First().Value.Value.Equals("CANCEL_EVENT"))
                    {
                        confirmationFlag = true;
                        prev_json        = json;
                        if (e.Result.Semantics.ElementAt(2).Value.Value.Equals("TOMORROW"))
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende cancelar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " amanhã às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende cancelar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " amanhã às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                        else if (e.Result.Semantics.ElementAt(2).Value.Value.Equals("TODAY"))
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende cancelar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " hoje às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende cancelar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " hoje às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                        else
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende cancelar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " do dia " + sToDateS(e.Result.Semantics.ElementAt(2).Value.Value.ToString()) + " às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende cancelar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " do dia " + sToDateS(e.Result.Semantics.ElementAt(2).Value.Value.ToString()) + " às " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                    }
                    else if (e.Result.Semantics.First().Value.Value.Equals("CANCEL_EVENTS_DAY"))
                    {
                        confirmationFlag = true;
                        prev_json        = json;
                        if (e.Result.Semantics.ElementAt(1).Value.Value.Equals("TOMORROW"))
                        {
                            t.Speak("Pretende cancelar os eventos de amanhã?");
                        }
                        else if (e.Result.Semantics.ElementAt(1).Value.Value.Equals("TODAY"))
                        {
                            t.Speak("Pretende cancelar os eventos de hoje?");
                        }
                        else
                        {
                            t.Speak("Pretende cancelar os eventos  do dia " + sToDateS(e.Result.Semantics.ElementAt(2).Value.Value.ToString()));
                        }
                    }
                    else if (e.Result.Semantics.First().Value.Value.Equals("POSTPONE_EVENT"))
                    {
                        confirmationFlag = true;
                        prev_json        = json;
                        if (e.Result.Semantics.ElementAt(2).Value.Value.Equals("TOMORROW"))
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende adiar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " amanhã às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende adiar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " amanhã às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                        else if (e.Result.Semantics.ElementAt(2).Value.Value.Equals("TODAY"))
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende adiar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " hoje às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende adiar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " hoje às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                        else
                        {
                            if (e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] == "0")
                            {
                                t.Speak("Pretende adiar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " do dia " + sToDateS(e.Result.Semantics.ElementAt(2).Value.Value.ToString()) + " às  " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas?");
                            }
                            else
                            {
                                t.Speak("Pretende adiar o evento " + e.Result.Semantics.ElementAt(1).Value.Value + " do dia " + sToDateS(e.Result.Semantics.ElementAt(2).Value.Value.ToString()) + " às " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[0] + " horas e " + e.Result.Semantics.ElementAt(3).Value.Value.ToString().Split(':')[1] + " minutos?");
                            }
                        }
                    }
                    else
                    {
                        exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);
                        mmic.Send(exNot);
                    }
                }
            }
        }
コード例 #23
0
        private void trySend_msg(string msg, int confidence)
        {
            var exNot = lce.ExtensionNotification(0 + "", 0 + "", confidence, msg);

            mmic.Send(exNot);
        }
コード例 #24
0
        /// <summary>
        /// Handles gesture detection results arriving from the sensor for the associated body tracking Id
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_GestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e)
        {
            using (var frame = this.vgbFrameReader.CalculateAndAcquireLatestFrame())
            {
                if (frame != null)
                {
                    //IReadOnlyDictionary<Gesture, DiscreteGestureResult> discreteResults = frame.DiscreteGestureResults;
                    var discreteResults = frame.DiscreteGestureResults;

                    if (discreteResults != null)
                    {
                        foreach (Gesture gesture in this.vgbFrameSource.Gestures)
                        {
                            if (gesture.GestureType == GestureType.Discrete)
                            {
                                DiscreteGestureResult result = null;
                                discreteResults.TryGetValue(gesture, out result);

                                if (result != null)
                                {
                                    if (gesture.Name.Equals(this.gesture_musicaAnterior))
                                    {
                                        anteriorDetected = result.Detected;
                                        anteriorConf     = result.Confidence;
                                    }
                                    else if (gesture.Name.Equals(this.gesture_musicaSeguinte))
                                    {
                                        seguinteDetected = result.Detected;
                                        seguinteConf     = result.Confidence;
                                    }
                                    else if (gesture.Name.Equals(this.gesture_musicaMute))
                                    {
                                        muteDetected = result.Detected;
                                        muteConf     = result.Confidence;
                                    }
                                    else if (gesture.Name.Equals(this.gesture_musicaReproduzir))
                                    {
                                        reproduzirDetected = result.Detected;
                                        reproduzirConf     = result.Confidence;
                                    }
                                    else if (gesture.Name.Equals(this.gesture_GoToHomeScreen))
                                    {
                                        homeScreenDetected = result.Detected;
                                        homeScreenConf     = result.Confidence;
                                    }
                                    else if (gesture.Name.Equals(this.gesture_musicaParar))
                                    {
                                        pararDetected = result.Detected;
                                        pararConf     = result.Confidence;
                                    }
                                }
                            }

                            this.GestureResultView.UpdateGestureResult(true, false, false, false, muteDetected, muteConf, false, reproduzirDetected, reproduzirConf, anteriorDetected, anteriorConf, seguinteDetected, seguinteConf, homeScreenDetected, homeScreenConf, pararDetected, pararConf);

                            if (homeScreenDetected)
                            {
                                if (!altHomeScreen)
                                {
                                    string json  = "{\"recognized\":[\"menuprincipal\"]}";
                                    var    exNot = LCE.ExtensionNotification("", "", 0, json);
                                    if (homeScreenConf >= 0.98f) //&& homeScreenConf <= 1.0f) // Intervalo de confiança para evitar envio de vários JSON
                                    {
                                        MMIC.Send(exNot);
                                        altHomeScreen = true;
                                        altMute       = false;
                                        altAnterior   = false;
                                        altSeguinte   = false;
                                        altReproduzir = false;
                                        altParar      = false;
                                    }
                                }
                            }
                            else if (muteDetected)
                            {
                                if (!altMute)
                                {
                                    string json  = "{\"recognized\":[\"volume\",\"mutevolume\"]}";
                                    var    exNot = LCE.ExtensionNotification("", "", 0, json);
                                    if (muteConf >= 0.85f) //&& muteConf <= 0.85f) // Intervalo de confiança para evitar envio de vários JSON
                                    {
                                        MMIC.Send(exNot);
                                        altHomeScreen = false;
                                        altMute       = true;
                                        altAnterior   = false;
                                        altSeguinte   = false;
                                        altReproduzir = false;
                                        altParar      = false;
                                    }
                                }
                            }
                            else if (anteriorDetected)
                            {
                                if (!altAnterior)
                                {
                                    string json  = "{\"recognized\":[\"musicaanterior\"]}";
                                    var    exNot = LCE.ExtensionNotification("", "", 0, json);
                                    if (anteriorConf >= 0.60f)// && retrocederConf <= 0.85f)
                                    {
                                        MMIC.Send(exNot);
                                        altHomeScreen = false;
                                        altMute       = false;
                                        altAnterior   = true;
                                        altSeguinte   = false;
                                        altReproduzir = false;
                                        altParar      = false;
                                    }
                                }
                            }
                            else if (seguinteDetected)
                            {
                                if (!altSeguinte)
                                {
                                    string json  = "{\"recognized\":[\"musicaseguinte\"]}";
                                    var    exNot = LCE.ExtensionNotification("", "", 0, json);
                                    if (seguinteConf >= 0.75f) //&& avancarConf <= 0.85f)
                                    {
                                        MMIC.Send(exNot);
                                        altHomeScreen = false;
                                        altMute       = false;
                                        altAnterior   = false;
                                        altSeguinte   = true;
                                        altReproduzir = false;
                                        altParar      = false;
                                    }
                                }
                            }
                            else if (reproduzirDetected)
                            {
                                if (!altReproduzir)
                                {
                                    string json  = "{\"recognized\":[\"reproduzir\"]}";
                                    var    exNot = LCE.ExtensionNotification("", "", 0, json);
                                    if (reproduzirConf >= 0.65f) //&& avancarConf <= 0.85f)
                                    {
                                        MMIC.Send(exNot);
                                        altHomeScreen = false;
                                        altMute       = false;
                                        altAnterior   = false;
                                        altSeguinte   = false;
                                        altReproduzir = true;
                                        altParar      = false;
                                    }
                                }
                            }
                            else if (pararDetected)
                            {
                                if (!altParar)
                                {
                                    string json  = "{\"recognized\":[\"parar\"]}";
                                    var    exNot = LCE.ExtensionNotification("", "", 0, json);
                                    if (pararConf >= 0.50f) //&& avancarConf <= 0.85f)
                                    {
                                        MMIC.Send(exNot);
                                        altHomeScreen = false;
                                        altMute       = false;
                                        altAnterior   = false;
                                        altSeguinte   = false;
                                        altReproduzir = false;
                                        altParar      = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #25
0
        private void GJson()
        {
            string gesture = "{ \"recognized\": ";

            if (reset == false)
            {
                if (this.gestureResultView.Headphones < 0.2 &&
                    this.gestureResultView.Hands_air < 0.3 &&
                    this.gestureResultView.Kill < 0.2 &&
                    this.gestureResultView.Play_Pause < 0.2 &&
                    this.gestureResultView.Swipe_Left < 0.2 &&
                    this.gestureResultView.Swipe_Right < 0.2 &&
                    this.gestureResultView.Jarbas_Init < 0.2)
                {
                    reset = true;
                    this.stackpanelBox.Background = new SolidColorBrush(Colors.Red);
                    this.stacklabel.Text          = "";
                }
            }
            else
            {
                if (this.gestureResultView.Hands_air > 0.8)
                {
                    gesture += "[\"" + "Hands_air\"] }";
                    gesture.Substring(0, gesture.Length - 2);

                    this.stackpanelBox.Background = new SolidColorBrush(Colors.Green);
                    this.stacklabel.Text          = "MODO LAZER";

                    var exNot = lce.ExtensionNotification("", "", this.gestureResultView.Hands_air, gesture);
                    mmic.Send(exNot);
                    reset = false;

                    Console.WriteLine(gesture);
                }
                else if (this.gestureResultView.Kill > 0.5)
                {
                    gesture += "[\"" + "Kill\"] }";
                    gesture.Substring(0, gesture.Length - 2);

                    this.stackpanelBox.Background = new SolidColorBrush(Colors.Green);
                    this.stacklabel.Text          = "MODO TRABALHO";

                    var exNot = lce.ExtensionNotification("", "", this.gestureResultView.Kill, gesture);
                    mmic.Send(exNot);
                    reset = false;

                    Console.WriteLine(gesture);
                }
                else if (this.gestureResultView.Headphones > 0.5)
                {
                    gesture += "[\"" + "Headphones\"] }";
                    gesture.Substring(0, gesture.Length - 2);



                    var exNot = lce.ExtensionNotification("", "", this.gestureResultView.Headphones, gesture);
                    mmic.Send(exNot);
                    reset = false;

                    Console.WriteLine(gesture);
                }
                else if (this.gestureResultView.Play_Pause > 0.5)
                {
                    gesture += "[\"" + "Play_Pause\"] }";
                    gesture.Substring(0, gesture.Length - 2);

                    this.stackpanelBox.Background = new SolidColorBrush(Colors.Green);
                    this.stacklabel.Text          = "SCREENSHOT";

                    var exNot = lce.ExtensionNotification("", "", this.gestureResultView.Play_Pause, gesture);
                    mmic.Send(exNot);
                    reset = false;

                    Console.WriteLine(gesture);
                }
                else if (this.gestureResultView.Swipe_Left > 0.5)
                {
                    gesture += "[\"" + "Swipe_Left\"] }";
                    gesture.Substring(0, gesture.Length - 2);

                    this.stackpanelBox.Background = new SolidColorBrush(Colors.Green);
                    this.stacklabel.Text          = "SWIPE ESQUERDA";

                    var exNot = lce.ExtensionNotification("", "", this.gestureResultView.Swipe_Left, gesture);
                    mmic.Send(exNot);
                    reset = false;

                    Console.WriteLine(gesture);
                }
                else if (this.gestureResultView.Swipe_Right > 0.4)
                {
                    gesture += "[\"" + "Swipe_Right\"] }";
                    gesture.Substring(0, gesture.Length - 2);

                    this.stackpanelBox.Background = new SolidColorBrush(Colors.Green);
                    this.stacklabel.Text          = "SWIPE DIREITA";

                    var exNot = lce.ExtensionNotification("", "", this.gestureResultView.Swipe_Right, gesture);
                    mmic.Send(exNot);
                    reset = false;

                    Console.WriteLine(gesture);
                }
                else if (this.gestureResultView.Jarbas_Init > 0.5)
                {
                    gesture += "[\"" + "Jarbas_init\"] }";
                    gesture.Substring(0, gesture.Length - 2);

                    //this.stackpanelBox.Background = new SolidColorBrush(Colors.Green);
                    //this.stacklabel.Text = "TERMINAR SESSÃO";

                    var exNot = lce.ExtensionNotification("", "", this.gestureResultView.Jarbas_Init, gesture);
                    mmic.Send(exNot);
                    reset = false;

                    Console.WriteLine(gesture);
                }

                /*if (this.gestureResultView.Headphones > 0.5 ||
                 *      this.gestureResultView.Hands_air > 0.7 ||
                 *      this.gestureResultView.Kill > 0.5 ||
                 *      this.gestureResultView.Play_Pause > 0.5 ||
                 *      this.gestureResultView.Swipe_Left > 0.5 ||
                 *      this.gestureResultView.Swipe_Right > 0.4 ||
                 *      this.gestureResultView.Jarbas_Init > 0.5)
                 * {
                 *  gesture += "\"" + "Kill" + "\":\"" + this.gestureResultView.Kill + "\", ";
                 *  gesture += "\"" + "Hands_air" + "\":\"" + this.gestureResultView.Hands_air + "\", ";
                 *  gesture += "\"" + "Headphones" + "\":\"" + this.gestureResultView.Headphones + "\", ";
                 *  gesture += "\"" + "Swipe_Right" + "\":\"" + this.gestureResultView.Swipe_Right + "\", ";
                 *  gesture += "\"" + "Swipe_Left" + "\":\"" + this.gestureResultView.Swipe_Left + "\", ";
                 *  gesture += "\"" + "Play_Pause" + "\":\"" + this.gestureResultView.Play_Pause + "\", ";
                 *  gesture += "\"" + "Jarbas_init" + "\":\"" + this.gestureResultView.Jarbas_Init + "\" ";
                 *
                 *  gesture.Substring(0, gesture.Length - 2);
                 *
                 *  var exNot = lce.ExtensionNotification("", "", 0.0f, gesture);
                 *  Console.WriteLine("Kill" + this.gestureResultView.Kill);
                 *  Console.WriteLine("Play_Pause" + this.gestureResultView.Play_Pause);
                 *  Console.WriteLine("Headphones" + this.gestureResultView.Headphones);
                 *  Console.WriteLine("Hands_air" + this.gestureResultView.Hands_air);
                 *  Console.WriteLine("Swipe_Left" + this.gestureResultView.Swipe_Left);
                 *  Console.WriteLine("Swipe_right" + this.gestureResultView.Swipe_Right);
                 *  Console.WriteLine("Jarbas_init" + this.gestureResultView.Jarbas_Init);
                 *  mmic.Send(exNot);
                 *  reset = false;
                 * }*/
            }
        }
コード例 #26
0
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            if (e.Result.Confidence <= 0.3)
            {
                tts.Speak("Desculpa, não consegui entender.");
                actualSemantic = null;
            }

            if (e.Result.Confidence < 0.4)
            {
                return;
            }

            if (e.Result.Confidence <= 0.7)
            {
                actualSemantic = e.Result.Semantics;

                if (e.Result.Semantics.ContainsKey("closeTab"))
                {
                    if (e.Result.Semantics["closeTab"].Value.ToString() == "CLOSE_TAB")
                    {
                        tts.Speak("Tem a certeza que pretende fechar o separador ?");
                        return;
                    }
                }

                if (e.Result.Semantics.ContainsKey("quitChrome"))
                {
                    if (e.Result.Semantics["quitChrome"].Value.ToString() == "QUIT_CHROME")
                    {
                        tts.Speak("Tem a certeza que pretende fechar o browser?");
                        return;
                    }
                }
                actualSemantic = null;
            }
            else
            {
                if (e.Result.Semantics.ContainsKey("closeTab"))
                {
                    if (e.Result.Semantics["closeTab"].Value.ToString() == "CLOSE_TAB")
                    {
                        actualSemantic = e.Result.Semantics;
                        tts.Speak("Tem a certeza que pretende fechar o separador?");
                        return;
                    }
                }

                if (e.Result.Semantics.ContainsKey("quitChrome"))
                {
                    if (e.Result.Semantics["quitChrome"].Value.ToString() == "QUIT_CHROME")
                    {
                        actualSemantic = e.Result.Semantics;
                        tts.Speak("Tem a certeza que pretende fechar o browser?");
                        return;
                    }
                }
            }

            SemanticValue semanticValue = null;

            if (actualSemantic != null)
            {
                if (e.Result.Semantics.ContainsKey("yes"))
                {
                    switch (e.Result.Semantics["yes"].Value.ToString())
                    {
                    case "AFFIRMATIVE":

                        if (e.Result.Semantics["yes"].Value.ToString() == "AFFIRMATIVE")
                        {
                            tts.Speak("Com certeza.");
                        }
                        break;
                    }
                }
                else
                {
                    if (e.Result.Semantics.ContainsKey("no"))
                    {
                        switch (e.Result.Semantics["no"].Value.ToString())
                        {
                        case "REJECT":
                            if (e.Result.Semantics["no"].Value.ToString() == "REJECT")
                            {
                                tts.Speak("Ok, desculpa, às vezes ando um pouco distraída.");
                            }
                            return;
                        }
                    }
                }

                semanticValue  = actualSemantic;
                actualSemantic = null;
            }
            else
            {
                semanticValue = e.Result.Semantics;
            }

            // if a command was recognized and the confirmation of a previous command was ignored by the user, disable it
            actualSemantic = null;


            string json = "{ \"recognized\": [";

            foreach (var resultSemantic in semanticValue)
            {
                json += "\"" + resultSemantic.Value.Value + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "] }";

            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            mmic.Send(exNot);
        }
コード例 #27
0
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            // ignore while the assistant is speaking
            if (assistantSpeaking)
            {
                return;
            }

            // ignore low confidance levels
            if (e.Result.Confidence < 0.4)
            {
                return;
            }

            // if confidence is between 40% and 60%
            if (e.Result.Confidence <= 0.6)
            {
                Speak("Desculpa, não consegui entender. Repete por favor..", 5);
                return;
            }

            // TO DOOOOOOOOOOOOOOOO
            // if confidence is between 60% and 80%, confirm explicitly

            /*if (e.Result.Confidence <= 0.80)
             * {
             *  Speak("Confirmar resposta..." , 2);
             * }*/

            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true, AssistantSpeaking = assistantSpeaking
            });

            // SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SHAPE","COLOR"]}
            string json = "{ \"recognized\": [";

            foreach (var resultSemantic in e.Result.Semantics)
            {
                json += "\"" + resultSemantic.Value.Value + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "] }";

            if (json.Contains("SEARCH"))
            {
                searchDone = true;
                Speak("Estou a pesquisar, só um segundo..", 2);
            }

            if (json.Contains("HOTEL"))
            {
                searchDone = true;
            }

            if (json.Contains("FILTER") && !searchDone)
            {
                Speak("É necessário definir um destino para pesquisa de hotéis primeiro..", 5);
                return;
            }

            if (json.Contains("HELP"))
            {
                RandomSpeak(new string[] {
                    "Experimenta dizer: Pesquisar voos em Madrid",
                    "Experimenta dizer: Pesquisar alojamento em Roma",
                    "Experimenta dizer: Pesquisar voos para Londres",
                }, 4);
                return;
            }

            if (json.Contains("CLOSE"))
            {
                pendingSemantic = e.Result.Semantics;
                Speak("Tens a certeza que pretendes sair da aplicação ?", 4);
                return;
            }

            // hold sematics from a previous command that is being confirmed or from the current command
            SemanticValue semanticValue = null;

            if (pendingSemantic != null)
            {
                //voice feedback for confirmation
                switch (e.Result.Semantics["action"].Value.ToString())
                {
                case "YES":
                    RandomSpeak(new string[] {
                        "Adeus, até uma próxima! ",
                    }, 4);
                    semanticValue   = pendingSemantic;
                    pendingSemantic = null;

                    json = "{ \"recognized\": [";
                    foreach (var resultSemantic in semanticValue)
                    {
                        json += "\"" + resultSemantic.Value.Value + "\", ";
                    }
                    json  = json.Substring(0, json.Length - 2);
                    json += "] }";

                    var exNot2 = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);
                    mmic.Send(exNot2);

                    Console.WriteLine("EXITING PROGRAM!");
                    Environment.Exit(0);
                    break;

                case "NO":
                    pendingSemantic = null;
                    RandomSpeak(new string[] {
                        "Percebi mal, peço desculpa.."
                    }, 4);
                    return;
                }
            }

            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            mmic.Send(exNot);
        }
コード例 #28
0
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });

            Tts t = new Tts();

            // ignore low confidance levels
            if (e.Result.Confidence < 0.2)
            {
                return;
            }

            // if confidence is between 20% and 50%
            if (e.Result.Confidence <= 0.5)
            {
                t.Speak("Desculpe, não consegui entender. Pode repetir, por favor...");
                return;
            }

            //SEND
            string json = "{ \"recognized\": [";

            foreach (var resultSemantic in e.Result.Semantics)
            {
                json += "\"" + resultSemantic.Value.Value + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "]";

            Console.WriteLine(json);

            json += ", \"keys\": [";
            foreach (var resultSemantic in e.Result.Semantics)
            {
                json += "\"" + resultSemantic.Key + "\", ";
            }
            json  = json.Substring(0, json.Length - 2);
            json += "] }";

            Console.WriteLine(json);

            // if confidence is between 50% and 65%
            if (e.Result.Confidence <= 0.65)
            {
                t.Speak("Não tenho a certeza do que disse. Disse " + e.Result.Text + "?");
                foreach (var resultSemantic in e.Result.Semantics)
                {
                    if (!resultSemantic.Value.Value.Equals("YES"))
                    {
                        jsonTmp            = json;
                        resultSemanticsTmp = e.Result.Semantics;
                    }
                }
                confidenceConfirmation = true;
                return;
            }

            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json);

            foreach (var resultSemantic in e.Result.Semantics)
            {
                if (resultSemantic.Value.Value.Equals("YES"))
                {
                    if (closeConfirmation)
                    {
                        gr = new Grammar(Environment.CurrentDirectory + "\\grammarInitial.grxml", "rootRule");
                        sre.UnloadAllGrammars();
                        sre.LoadGrammar(gr);
                        closeConfirmation = false;
                    }
                    if (confidenceConfirmation)
                    {
                        cleanAllConfirmations();
                        foreach (var resultSemanticTmp in resultSemanticsTmp)
                        {
                            chooseCommand(t, resultSemanticTmp, jsonTmp);
                        }
                        confidenceConfirmation = false;
                    }
                    if (removeSlideConfirmation)
                    {
                        removeSlideConfirmation = false;
                    }
                    exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, jsonTmp);
                }
                else if (resultSemantic.Value.Value.Equals("NO"))
                {
                    t.Speak("Devo ter percebido mal!");
                    cleanAllConfirmations();
                }
                else
                {
                    cleanAllConfirmations();
                    chooseCommand(t, resultSemantic, json);
                }
            }

            mmic.Send(exNot);
        }
コード例 #29
0
ファイル: SpeechMod.cs プロジェクト: T-Almeida/IM_Fusion
        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            onRecognized(new SpeechEventArg()
            {
                Text = e.Result.Text, Confidence = e.Result.Confidence, Final = true
            });


            StringBuilder json = new StringBuilder("{");

            json.Append("\"source\":\"VOZ\",");

            if (grYesNo.Enabled)
            {
                json.Append("\"type\":\"YESNO\",");
                if (e.Result.Confidence > 0.80)
                {
                    resetGrammar();
                    json.Append("\"confidence\":\"GOOD\",");
                }
                else
                {
                    json.Append("\"confidence\":\"BAD\",");
                }
            }
            else
            {
                resetGrammar();
                json.Append("\"type\":\"NORMAL\",");

                if (e.Result.Confidence > 0.7)
                {
                    json.Append("\"confidence\":\"GOOD\",");
                }
                else if (e.Result.Confidence > 0.30)
                {
                    json.Append("\"confidence\":\"MEDIUM\",");

                    //handle special characters
                    string inputText = e.Result.Text;
                    foreach (var t in specialCharacters)
                    {
                        inputText = inputText.Replace(t.Item1, t.Item2);
                    }

                    json.Append("\"inputText\":\"" + inputText + "\",");
                    switchYesNoGrammar(); //this method change grammars Enabled Method
                }
                else
                {
                    json.Append("\"confidence\":\"BAD\",");
                }
            }


            //SEND
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["SHAPE","COLOR"]}
            json.Append("\"recognized\": [");
            foreach (var resultSemantic in e.Result.Semantics)
            {
                //handle special characters

                string rSemantic = (string)resultSemantic.Value.Value;
                foreach (var t in specialCharacters)
                {
                    rSemantic = rSemantic.Replace(t.Item1, t.Item2);
                }

                json.Append("\"" + rSemantic + "\",");
            }
            json.Remove(json.Length - 1, 1);

            json.Append("]}");

            Console.WriteLine(json.ToString());

            var exNot = lce.ExtensionNotification(e.Result.Audio.StartTime + "", e.Result.Audio.StartTime.Add(e.Result.Audio.Duration) + "", e.Result.Confidence, json.ToString());

            mmic.Send(exNot);
        }