public override void enviarMensaje(MensajeOSC msgosc) { try { byte[] bytes = null; bytes = Encoding.ASCII.GetBytes(msgosc.getMensajeFormatoOSC()); // MessageBox.Show(msgosc.getMensajeFormatoOSC()+ "tamaño del buffer: "+ bytes.Length); //Send it to the server clientSocket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(OnSend), null); } catch (Exception) { MessageBox.Show("Unable to send message to the server.", "ERROR 5 EN Client "); } }
} //end funcion obtenerReconocedor //************************************************************************** // This method matches the voice commands with the words of the txt //************************************************************************** private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { // int pos; string comandoreconocido = null; commandslist = gramaticadinamica.getCommandsList(); // Speech utterance confidence below which we treat speech as if it hadn't been heard niveldeconfianza = e.Result.Confidence; if (e.Result.Confidence >= 0.7) //confidence level: 0 to 1. For more accuracy results please change tge 0.7 for 0.9 or 0.95. { //If the voice command is "salir" (exit) or "cerrar" (close) The application will close itself if ((e.Result.Words[0].Text == "proche") || (e.Result.Words[0].Text == "laisser")) { ventana.Close(); } else //If the first word pronounced is "assistant" (keyword to avoid false possitives) if (e.Result.Words[0].Text == palabraclave) //Palabra clave = "assistant" you can change it in the variables section at the beginning of this class. { comandoreconocido = getRecognizedCommand(e.Result.Words); //Obtains all the words recognized ventana.label6.Content = comandoreconocido; if (hayMatching(e.Result.Words, commandslist)) //if the word detected is a command from the txt file/ grammar { int pos = gramaticadinamica.getId(comandoreconocido); //This is to obtain the id (line) of the command recognized. It is used as a parameter to execute an Arduino function MessageBox.Show("You have said " + comandoreconocido); msgosc = new MensajeOSC(pos, "voix", e.Result.Confidence, comandoreconocido); //The message sent to Arduino has an OSC protocol format servidor.enviarMensaje(msgosc); //Sends the msg to the server. To execute the Arduino funcionality. } else { //If the command is not recognized but the keyward was, the audiostream is rejected estado = "The command could not be recognized"; RejectSpeech(estado); } } else { //If the word was not "assistant" all the recognized stream is rejected estado = "Plsease, remember using the keyword: " + palabraclave; RejectSpeech(estado); } } else { //If the confidence detected is too low, all the audio stream is rejected estado = "Rejected " + e.Result.Text + " The conficende level was too low " + e.Result.Confidence; RejectSpeech(estado); } }
//This method gives functionality to the recognized gestures private void sensor_NewPerson(object sender, GestureDetector.Events.NewPersonEventArgs e) { //ONsWIPE= right hand, moving to the right e.Person.OnSwipe += delegate(object sender1, GestureEventArgs args) { if (ventana.luzcocina.Visibility == Visibility.Visible) { ventana.luzcocina.Visibility = Visibility.Hidden; msgosc = new MensajeOSC(2, "gesture", 1, "turn off light"); //The message sent to Arduino has an OSC protocol format servidor.enviarMensaje(msgosc); //Sends the msg to the server. To execute the Arduino funcionality. } }; //OnSwipeRightToLeft = right hand moving to the left e.Person.OnSwipeRightToLeft += delegate(object sender1, GestureEventArgs args) { if (ventana.luzcocina.Visibility == Visibility.Hidden) { ventana.luzcocina.Visibility = Visibility.Visible; msgosc = new MensajeOSC(1, "gesto", 1, "turn on light"); //The message sent to Arduino has an OSC protocol format servidor.enviarMensaje(msgosc); //Sends the msg to the server. To execute the Arduino funcionality. } }; }
public override void enviarMensaje(MensajeOSC msg) { //msg = new MensajeOSC ( id, tipo, confidence, comando); MessageBox.Show("The message is: " + msg.getMensajeFormatoOSC()); puertousb.Write(/*id.ToString()*/ "1"); }
public abstract void enviarMensaje(MensajeOSC msgosc);