private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            TB_recognizedText.Background = Brushes.LightGreen;
            TB_recognizedText.Text       = Capitalize(e.Result.Text);

            SemanticValue semantics = e.Result.Semantics;

            // La frase ¿Hay algun vuelo para mañana? añade una variable a la semantica para indicar que se ha reconocido esa frase
            // Si dicha variable se encuentra en la gramatica se muestran los destinos disponibles y si no se extrae más información de la semantica
            if (semantics.ContainsKey("TomorrowFlights"))
            {
                SP_destinationsAvaliable.Visibility = Visibility.Visible;
            }
            else
            {
                ChangeStackPanelsVisibility(true);
                // Por defecto Castellón como origen, una mejora seria indicarlo en la gramatica
                TB_origin.Text      = "Castellón";
                TB_destination.Text = semantics["Destination"].Value.ToString();
                TB_type.Text        = semantics["Type"].Value.ToString();

                if (semantics.ContainsKey("Price"))
                {
                    TB_price.Text = semantics["Price"].Value.ToString();
                }
            }

            B_speak.IsEnabled = true;
        }
        private void SpeechRecognitionService_SpeechRecognized(System.Speech.Recognition.SpeechRecognizedEventArgs e)
        {
            SemanticValue semantics = e.Result.Semantics;

            if (semantics.ContainsKey(NEW_KEY))
            {
                if (semantics.ContainsKey(LEVEL_KEY))
                {
                    switch (semantics[LEVEL_KEY].Value.ToString())
                    {
                    case "facil":
                        RB_Easy.IsChecked = true;
                        break;

                    case "media":
                        RB_Med.IsChecked = true;
                        break;

                    case "dificil":
                        RB_Hard.IsChecked = true;
                        break;
                    }
                }
                NuevaPartida();
            }
            else if (semantics.ContainsKey(RESTART_KEY))
            {
                ReiniciarPartida();
            }
            else if (semantics.ContainsKey(PROBABLE_KEY))
            {
                CB_VerPosibles.IsChecked = mostrarPosibles = bool.Parse(semantics[PROBABLE_KEY].Value.ToString());
                ActualizaPosibles();
            }
            else
            {
                int newNumber = 0;

                if (semantics.ContainsKey(NUMBER_KEY))
                {
                    newNumber = int.Parse(semantics[NUMBER_KEY].Value.ToString());
                }

                int row    = LEFT_HEADER.IndexOf(semantics["Row"].Value.ToString());
                int column = int.Parse(semantics["Column"].Value.ToString()) - 1;

                PonSelecciónEn(row, column);
                _s[_filaActual, _columnaActual] = newNumber;
            }
        }
Beispiel #3
0
        private static List <string> parseSemanticList(string key, SemanticValue semantic)
        {
            if (semantic.ContainsKey(key))
            {
                List <string> list = new List <string>();

                // remove weird object Object from the ToString
                int    index  = semantic[key].Value.ToString().IndexOf("[object Object]");
                string result = (index < 0)
                    ? semantic[key].Value.ToString()
                    : semantic[key].Value.ToString().Remove(index, "[object Object]".Length);

                string[] resultPieces = result.Split('{', '}', ' ');

                foreach (string piece in resultPieces)
                {
                    // go through each piece of the semantic and add the non-trivial pieces to our list
                    if (piece != "")
                    {
                        list.Add(piece);
                    }
                }

                return(list);
            }

            return(null);
        }
Beispiel #4
0
        private static string parseSemantic(string key, SemanticValue semantic)
        {
            if (semantic.ContainsKey(key))
            {
                // remove weird object Object from the ToString
                int    index  = semantic[key].Value.ToString().IndexOf("[object Object]");
                string result = (index < 0)
                    ? semantic[key].Value.ToString()
                    : semantic[key].Value.ToString().Remove(index, "[object Object]".Length);

                string[] resultPieces = result.Split('{', '}', ' ');

                foreach (string piece in resultPieces)
                {
                    // go through each piece of the semantic and add the non-trivial pieces to our list
                    if (piece != "")
                    {
                        // return the first valid piece, shouldn't be a list
                        return(piece);
                    }
                }
            }

            return(null);
        }
Beispiel #5
0
        private static List <string> ParseSemanticList(string key, SemanticValue semantic)
        {
            if (semantic.ContainsKey(key))
            {
                List <string> list = new List <string>();

                int    index  = semantic[key].Value.ToString().IndexOf("[object Object]");
                string result = (index < 0)
                                        ? semantic[key].Value.ToString()
                                        : semantic[key].Value.ToString().Remove(index, "[object Object]".Length);

                string[] resultPieces = result.Split('{', '}', ' ');

                foreach (string piece in resultPieces)
                {
                    if (piece != "")
                    {
                        list.Add(piece);
                    }
                }

                return(list);
            }

            return(null);
        }
        private string GetConfidence(SemanticValue Semantics, string keyName)
        {
            string result = "";

            if (Semantics.ContainsKey(keyName))
            {
                result = Semantics[keyName].Confidence.ToString("0.0000");
            }
            return(result);
        }
        private string GetValue(SemanticValue Semantics, string keyName)
        {
            string result = "";

            if (Semantics.ContainsKey(keyName))
            {
                result = Semantics[keyName].Value.ToString();
            }
            return(result);
        }
Beispiel #8
0
        void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //obtenemos un diccionario con los elementos semánticos
            SemanticValue semantics = e.Result.Semantics;

            string            rawText = e.Result.Text;
            RecognitionResult result  = e.Result;

            if (semantics.ContainsKey("rgb"))
            {
                this.BackColor = Color.FromArgb((int)semantics["rgb"].Value);
                Update();
            }
            if (semantics.ContainsKey("escribir"))
            {
                this.label1.Text = "Esto es un texto.";
                Update();
            }
            else if (semantics.ContainsKey("remove"))
            {
                if (semantics["remove"].Value.ToString() == "text")
                {
                    this.label1.Text = "";
                }
                else if (semantics["remove"].Value.ToString() == "time")
                {
                    this.label2.Text = "";
                }
            }
            else if (semantics.ContainsKey("time"))
            {
                var now = DateTime.Now;
                this.label2.Text = now.ToString("HH:mm");
                Update();
                synth.Speak("Son las " + now.Hour + " y " + now.Minute);
            }
            else
            {
                this.label1.Text = "Comando de voz no admitido.";
            }
        }
Beispiel #9
0
        /// <summary> Event handler tasked with routing the recognized voice commands. </summary>
        /// <param name="sender"> The object that caused the event. </param>
        /// <param name="e"> The speech recognized commands. </param>
        private void Recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            SemanticValue semantics = e.Result.Semantics;

            this.logger.LogInformation("Recognized Text: " + e.Result.Text);

            if (semantics.ContainsKey("PowerOn"))
            {
                this.PowerOn();
            }

            if (semantics.ContainsKey("PowerOff"))
            {
                this.PowerOff();
            }

            if (semantics.ContainsKey("CurrentTemperature"))
            {
                this.CurrentTemperatureCommand();
            }

            if (semantics.ContainsKey("HeatRoom"))
            {
                SemanticValue heatRoomSemanticValue = semantics["HeatRoom"];
                double        targetTemperature     = double.Parse(heatRoomSemanticValue["TargetTemp"].Value.ToString());

                Task.WaitAny(this.StartHeatingMode(targetTemperature));
            }

            if (semantics.ContainsKey("CoolRoom"))
            {
                SemanticValue coolRoomSemanticValue = semantics["CoolRoom"];
                double        targetTemperature     = double.Parse(coolRoomSemanticValue["TargetTemp"].Value.ToString());

                Task.WaitAny(this.StartCoolingMode(targetTemperature));
            }

            if (semantics.ContainsKey("ChangeRoomTemp"))
            {
                SemanticValue coolRoomSemanticValue = semantics["ChangeRoomTemp"];
                double        targetTemperature     = double.Parse(coolRoomSemanticValue["TargetTemp"].Value.ToString());

                Task.WaitAny(this.ChangeRoomTemperatureCommand(targetTemperature));
            }
        }
Beispiel #10
0
        private static List<string> parseSemanticList(string key, SemanticValue semantic)
        {
            if (semantic.ContainsKey(key))
            {
                List<string> list = new List<string>();

                // remove weird object Object from the ToString
                int index = semantic[key].Value.ToString().IndexOf("[object Object]");
                string result = (index < 0)
                    ? semantic[key].Value.ToString()
                    : semantic[key].Value.ToString().Remove(index, "[object Object]".Length);

                string[] resultPieces = result.Split('{', '}', ' ');

                foreach (string piece in resultPieces)
                {
                    // go through each piece of the semantic and add the non-trivial pieces to our list
                    if (piece != "")
                    {
                        list.Add(piece);
                    }
                }

                return list;
            }

            return null;
        }
Beispiel #11
0
        private static string parseSemantic(string key, SemanticValue semantic)
        {
            if (semantic.ContainsKey(key))
            {
                // remove weird object Object from the ToString
                int index = semantic[key].Value.ToString().IndexOf("[object Object]");
                string result = (index < 0)
                    ? semantic[key].Value.ToString()
                    : semantic[key].Value.ToString().Remove(index, "[object Object]".Length);

                string[] resultPieces = result.Split('{', '}', ' ');

                foreach (string piece in resultPieces)
                {
                    // go through each piece of the semantic and add the non-trivial pieces to our list
                    if (piece != "")
                    {
                        // return the first valid piece, shouldn't be a list
                        return piece;
                    }
                }
            }

            return null;
        }
Beispiel #12
0
        private void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            SemanticValue semantics = e.Result.Semantics;
            string        text      = e.Result.Text;

            //Orders
            if (text.Contains("Cierra") || e.Result.Text.Contains("Salir") || e.Result.Text.Contains("Cerrar"))
            {
                CloseApplication();
            }
            else if (text.Contains("siguiente"))
            {
                NextCuestion();
            }
            else if (text.Contains("ayuda"))
            {
                NeedHelp();
            }
            else if (text.Contains("Empezar"))
            {
                BeginAgain();
            }
            else if (text.Contains("y"))
            {
                if (resultsDialog)
                {
                    return;
                }
                currentQuestions = new List <string>();
                //Control order
                if (semantics["topic1"].Value.ToString().Equals("animales") && semantics["topic2"].Value.ToString().Equals("colores"))
                {
                    currentTopic = "animales_colores";
                    currentQuestions.AddRange(animalsColorsList);
                    UpdateCuestion();
                }
                else if (semantics["topic1"].Value.ToString().Equals("colores") && semantics["topic2"].Value.ToString().Equals("animales"))
                {
                    currentTopic = "animales_colores";
                    currentQuestions.AddRange(animalsList);
                    UpdateCuestion();
                }
                else if (semantics["topic1"].Value.ToString().Equals(semantics["topic2"].Value.ToString()))
                {
                    ShowError();
                }
            }
            else if (semantics.ContainsKey("topic1"))
            {
                if (resultsDialog)
                {
                    return;
                }
                currentQuestions = new List <string>();
                if (semantics["topic1"].Value.ToString().Equals("animales"))
                {
                    currentTopic = "animales";
                    currentQuestions.AddRange(animalsList);
                    UpdateCuestion();
                }
                else if (semantics["topic1"].Value.ToString().Equals("colores"))
                {
                    currentTopic = "colores";
                    currentQuestions.AddRange(colorsList);
                    UpdateCuestion();
                }
            }
            else if (text.Contains("de color"))
            {
                if (resultsDialog)
                {
                    return;
                }
                if (currentTopic.Equals("animales_colores"))
                {
                    CheckCorrect(semantics["animals"].Value.ToString() + "_" + semantics["colors"].Value.ToString());
                }
            }

            else if (text.Contains("Este animal es un"))
            {
                if (resultsDialog)
                {
                    return;
                }
                //Check if the topic is animales
                if (currentTopic.Equals("animales"))
                {
                    CheckCorrect(semantics["animals"].Value.ToString());
                }
            }
            else if (text.Contains("Este color es el"))
            {
                if (resultsDialog)
                {
                    return;
                }
                //Check if the topic is colores
                if (currentTopic.Equals("colores"))
                {
                    CheckCorrect(semantics["colors"].Value.ToString());
                }
            }
            else if (text.Contains("dificultad"))
            {
                if (text.Contains("aumentar"))
                {
                    if (difficultyLevel < 2)
                    {
                        difficultyLevel++;
                        SetQuestionStatement();
                    }
                }
                else
                {
                    if (difficultyLevel > 0)
                    {
                        difficultyLevel--;
                        SetQuestionStatement();
                    }
                }
            }
        }
Beispiel #13
0
        private static void Listen()
        {
            while (run)
            {
                RecognitionResult result = activationRecognizer.Recognize();

                if (result != null)
                {
                    Console.WriteLine("Reconocido: " + result.Text);

                    synth.Speak("Te escucho");

                    RosanaCommand command = new RosanaCommand();

                    CommandResult commandResult = command.Listen();

                    if (commandResult.Success)
                    {
                        Console.WriteLine("Reconocido: " + commandResult.Result.Text);

                        synth.Speak("En seguida");

                        SemanticValue semantics = commandResult.Result.Semantics;

                        if (!semantics.ContainsKey("frase"))
                        {
                            Console.WriteLine("Error: no se ha reconocido ninguna frase"); // Should not happen in any case
                        }
                        else
                        {
                            SemanticValue frase = semantics["frase"];

                            string comando = (string)frase.Value;

                            if (RosanaCommand.ABRIR.Equals(comando))
                            {
                                System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                                startInfo.FileName    = "cmd.exe";
                                startInfo.Arguments   = "/C " + (string)frase[RosanaCommand.ABRIR].Value;
                                process.StartInfo     = startInfo;
                                process.Start();
                            }
                            else if (RosanaCommand.CHISTE.Equals(comando))
                            {
                                synth.Speak("Van dos y se cae el de en medio");
                            }
                            else if (RosanaCommand.CURIOSIDAD.Equals(comando))
                            {
                                synth.Speak("¿Sabías que los cocodrilos no pueden sacar la lengua?");
                            }
                            else if (RosanaCommand.DESCANSAR.Equals(comando))
                            {
                                synth.Speak("Adiós");
                                run = false;
                            }
                        }
                    }
                    else
                    {
                        synth.Speak("No te he entendido");
                    }
                }
            }
        }
 /// <summary>
 /// Check the recognition result for both a species name and a length value
 /// </summary>
 /// <param name="semanticValue"></param>
 /// <returns></returns>
 public static bool HasSpeciesAndLength(SemanticValue semanticValue)
 {
     bool hasSpecies = semanticValue.ContainsKey(SpeciesKey);
     bool hasLength = semanticValue.ContainsKey(LengthKey);
     System.Diagnostics.Debug.WriteLine("HasSpecies? {0}  HasLength? {1}", hasSpecies, hasLength);
     return hasSpecies && hasLength;
 }
Beispiel #15
0
        void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //obtenemos un diccionario con los elementos semánticos
            SemanticValue semantics = e.Result.Semantics;

            string            rawText = e.Result.Text;
            RecognitionResult result  = e.Result;

            if (!semantics.ContainsKey("Lugares"))
            {
                if (!semantics.ContainsKey("Poner"))
                {
                    if (!semantics.ContainsKey("Apagar"))
                    {
                        if (!semantics.ContainsKey("Cambiar"))
                        {
                            if (!semantics.ContainsKey("Encender"))
                            {
                            }
                            else
                            {
                                String musica = ((string)semantics["musica"].Value);
                                synth.Speak("Poniendo " + musica);
                                switch (musica)
                                {
                                case "musica":
                                    if (player.SoundLocation == "")
                                    {
                                        player.SoundLocation = "../../Resources/musica.wav";
                                    }
                                    player.Load();
                                    player.Play();
                                    break;

                                    /*case "villancico":
                                     *  player.SoundLocation = "../../Resources/Jingle Bells.wav";
                                     *  player.Load();
                                     *  player.Play();
                                     *  break;*/
                                }
                            }
                        }
                        else
                        {
                            String sexo = ((string)semantics["Sexo"].Value);
                            synth.Speak("Cambiando " + sexo);
                            switch (sexo)
                            {
                            case "Chico":
                                cuerpo.Image = DressDoll.Properties.Resources.Boy;
                                ChicaOn      = false;
                                break;

                            case "Chica":
                                cuerpo.Image = DressDoll.Properties.Resources.Girl_1;
                                ChicaOn      = true;
                                break;

                            case "Sexo":
                                if (ChicaOn)
                                {
                                    cuerpo.Image = DressDoll.Properties.Resources.Boy;
                                    ChicaOn      = false;
                                }
                                else
                                {
                                    cuerpo.Image = DressDoll.Properties.Resources.Girl_1;
                                    ChicaOn      = true;
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (semantics.ContainsKey("musica"))
                        {
                            synth.Speak("Apagando música");
                            player.Stop();
                        }
                    }
                }
                else
                {
                    if (semantics.ContainsKey("partesAbajo"))
                    {
                        String ropa = ((string)semantics["partesAbajo"].Value);
                        synth.Speak("Poniendo " + ropa);
                        if (doll.conflictoRopa("ParteAbajo"))
                        {
                            //quitar parte parteEntera.Image
                            parteEntera.Image = null;
                            //poner a false en doll
                            doll.ParteEntera = false;
                        }
                        switch (ropa)
                        {
                        case "Falda":
                            parteAbajo.Image = DressDoll.Properties.Resources.Falda;
                            break;

                        case "Pantalones":
                            parteAbajo.Image = DressDoll.Properties.Resources.Pantalones;
                            break;

                        case "Pantalones cortos":
                            parteAbajo.Image = DressDoll.Properties.Resources.Shorts;
                            break;
                        }
                        //poner a true  parte Abajo doll
                        doll.ParteAbajo = true;
                    }
                    else if (semantics.ContainsKey("partesArriba"))
                    {
                        String ropa = ((string)semantics["partesArriba"].Value);
                        synth.Speak("Poniendo " + ropa);
                        if (doll.conflictoRopa("ParteArriba"))
                        {
                            //quitar parte parteEntera.Image
                            parteEntera.Image = null;
                            //poner a false en doll
                        }
                        switch (ropa)
                        {
                        case "Camiseta":
                            parteArriba.Image = DressDoll.Properties.Resources.Camiseta;
                            break;

                        case "Chaqueta":
                            parteArriba.Image = DressDoll.Properties.Resources.Chaqueta;
                            break;

                        case "Abrigo":
                            parteArriba.Image = DressDoll.Properties.Resources.Abrigo;
                            break;

                        case "Blusa":
                            parteArriba.Image = DressDoll.Properties.Resources.Blusa;
                            break;

                        case "Jersey":
                            parteArriba.Image = DressDoll.Properties.Resources.Jersey;
                            break;
                        }
                        //poner a true  parte Arriba doll
                        doll.ParteArriba = true;
                    }
                    else if (semantics.ContainsKey("zapatos"))
                    {
                        String ropa = ((string)semantics["zapatos"].Value);
                        synth.Speak("Poniendo " + ropa);
                        switch (ropa)
                        {
                        case "Zapatos":
                            zapatos.Image = DressDoll.Properties.Resources.Zapatos;
                            break;

                        case "Botas":
                            zapatos.Image = DressDoll.Properties.Resources.Botas;
                            break;

                        case "Sandalias":
                            zapatos.Image = DressDoll.Properties.Resources.Sandalias;
                            break;
                        }
                        // poner a true  zapatos doll
                        doll.Zapatos = true;
                    }
                    else if (semantics.ContainsKey("parteEntera"))
                    {
                        String ropa = ((string)semantics["parteEntera"].Value);
                        synth.Speak("Poniendo " + ropa);
                        if (doll.conflictoRopa("ParteEntera"))
                        {
                            //quitar parte  Arriba y abajo parteEntera.Image
                            parteArriba.Image = null;
                            parteAbajo.Image  = null;
                            //poner a false las dos en doll
                            doll.ParteArriba = false;
                            doll.ParteAbajo  = false;
                        }
                        switch (ropa)
                        {
                        case "Vestido":
                            parteEntera.Image = DressDoll.Properties.Resources.Vestido;
                            break;

                        case "Playero":
                            parteEntera.Image = DressDoll.Properties.Resources.Playero;
                            break;

                        case "Bikini":
                            parteEntera.Image = DressDoll.Properties.Resources.Bikini;
                            break;

                        case "Bañador":
                            parteEntera.Image = DressDoll.Properties.Resources.Bañador;
                            break;

                        case "Disfraz navideño":
                            parteEntera.Image    = DressDoll.Properties.Resources.TrajeFestivo;
                            this.BackgroundImage = DressDoll.Properties.Resources.navidad;
                            //musica
                            player.SoundLocation = "../../Resources/Jingle Bells.wav";
                            player.Load();
                            player.Play();
                            break;

                        case "Disfraz de pirata":
                            parteEntera.Image    = DressDoll.Properties.Resources.disfraz;
                            this.BackgroundImage = DressDoll.Properties.Resources.barco;
                            //musica
                            player.SoundLocation = "../../Resources/pirata.wav";
                            player.Load();
                            player.Play();
                            break;
                        }
                        // poner a true  parte Entera doll
                        doll.ParteEntera = true;
                    }
                }

                if (semantics.ContainsKey("Quitar"))
                {
                    if (semantics.ContainsKey("partesArriba"))
                    {
                        synth.Speak("Quitando " + semantics["partesArriba"].Value);
                        parteArriba.Image = null;
                    }
                    else if (semantics.ContainsKey("partesAbajo"))
                    {
                        synth.Speak("Quitando " + semantics["partesAbajo"].Value);
                        parteAbajo.Image = null;
                    }
                    else if (semantics.ContainsKey("zapatos"))
                    {
                        synth.Speak("Quitando " + semantics["zapatos"].Value);
                        zapatos.Image = null;
                    }
                    else if (semantics.ContainsKey("parteEntera"))
                    {
                        synth.Speak("Quitando " + semantics["parteEntera"].Value);
                        parteEntera.Image = null;
                    }
                }
            }
            else
            {
                String lugar = ((string)semantics["Lugares"].Value);
                synth.Speak("Yendo a " + lugar);
                switch (lugar)
                {
                case "playa":
                    this.BackgroundImage = DressDoll.Properties.Resources.playa;
                    break;

                case "parque":
                    this.BackgroundImage = DressDoll.Properties.Resources.parque;
                    break;

                case "barco":
                    this.BackgroundImage = DressDoll.Properties.Resources.barco;
                    break;

                case "casa":
                    this.BackgroundImage = DressDoll.Properties.Resources.navidad;
                    break;

                case "cine":
                    this.BackgroundImage = DressDoll.Properties.Resources.cine;
                    break;

                case "clase":
                    this.BackgroundImage = DressDoll.Properties.Resources.clase;
                    break;
                }
            }
        }