void speechEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { const double ConfidenceThreshold = 0.3; if (e.Result.Confidence >= ConfidenceThreshold) { if (e.Result.Semantics.Value != null) { string semValue = e.Result.Semantics.Value.ToString(); switch (semValue) { case "CALIB_CALIBRATE": mainEngine.AddTextToLog("SpeechRec: " + semValue); if (mainEngine.GetAppState() == ApplicationState.Ready) { mainEngine.SetAppState(ApplicationState.Calibration); mainEngine.service.send(Orders.CALIBRATE); // no i komunikat do klienta... } else { // jakies inne przypadki? np. ponowna kalibracja czy cos... } break; case "CALIB_MARK": mainEngine.AddTextToLog("SpeechRec: " + semValue); if (mainEngine.GetAppState() == ApplicationState.Calibration) { mainEngine.GetCalibrator().SetNextCalibrationPoint( mainEngine.GetSkeletonController().GetRightHandCoord()); if (mainEngine.GetAppState() == ApplicationState.Calibrated) { mainEngine.AddTextToLog("skalibrowane"); mainEngine.service.send(Orders.DONE); } else if (mainEngine.GetAppState() == ApplicationState.Calibration) { mainEngine.service.send(Orders.MARK); } } else { // cos poszlo zle... } break; case "ONN_MOVE": mainEngine.AddTextToLog("SpeechRec: " + semValue); break; case "ONN_THERE": mainEngine.AddTextToLog("SpeechRec: " + semValue); if (mainEngine.GetAppState() == ApplicationState.Working) { mainEngine.GetObjectManager().SelectedMoveTo(mainEngine.GetSkeletonController().GetRightHandCoord()); // no i komunikat do klienta... } else { // ... } break; case "ONN_REMOVE": mainEngine.AddTextToLog("SpeechRec: " + semValue); if (mainEngine.GetAppState() == ApplicationState.Working) { if (mainEngine.GetObjectManager().GetSelectedObject() != null) { mainEngine.service.sendRemoveObject(mainEngine.GetObjectManager().GetSelectedObject().GetObjectName()); mainEngine.GetObjectManager().RemoveSelectedObject(); } // no i komunikat do klienta... } else { // ... } break; } } else { var semVal = e.Result.Semantics; if (semVal.ContainsKey("OWN_MOVE_NAME")) { mainEngine.AddTextToLog("SpeechRec: move " + semVal["OWN_MOVE_NAME"].Value); if (mainEngine.GetAppState() == ApplicationState.Working) { string name = semVal["OWN_MOVE_NAME"].Value.ToString(); mainEngine.GetObjectManager().MoveTo(name, mainEngine.GetSkeletonController().GetRightHandCoord()); SingleObject so = mainEngine.GetObjectManager().GetUsedObjectByName(name); if (so != null) { mainEngine.service.sendMoveObject(so.GetObjectName(), so.GetScreenCentroidPosition().Y, so.GetScreenCentroidPosition().X); } } else { // ... } } else if (semVal.ContainsKey("OWN_NEW_NAME")) { mainEngine.AddTextToLog("SpeechRec: new " + semVal["OWN_NEW_NAME"].Value); if (mainEngine.GetAppState() == ApplicationState.Working) { mainEngine.GetObjectManager().AddUsedObject(semVal["OWN_NEW_NAME"].Value.ToString(), mainEngine.GetSkeletonController().GetRightHandCoord()); SingleObject so = mainEngine.GetObjectManager().GetUsedObjectByName(semVal["OWN_NEW_NAME"].Value.ToString()); so.SetScreenPosition(mainEngine.GetCalibrator().ScaleKinectPositionToScreen(so.GetCentroidPosition())); mainEngine.service.sendCreateObject(so.GetObjectName(), so.GetObjectType(), so.GetScreenCentroidPosition().Y, so.GetScreenCentroidPosition().X); } else { // ... } } else if (semVal.ContainsKey("OWN_REMOVE_NAME")) { mainEngine.AddTextToLog("SpeechRec: remove " + semVal["OWN_REMOVE_NAME"].Value); if (mainEngine.GetAppState() == ApplicationState.Working) { mainEngine.GetObjectManager().RemoveUsedObject(semVal["OWN_REMOVE_NAME"].Value.ToString()); mainEngine.service.sendRemoveObject(semVal["OWN_REMOVE_NAME"].Value.ToString()); } else { } } } } }
protected override void OnMessage(MessageEventArgs e) { var msg = ""; JObject myJson = JObject.Parse(e.Data); System.Diagnostics.Debug.WriteLine("onmes: " + myJson.ToString()); if (myJson["type"].ToString().Contains("configure:")) { if (myJson["type"].ToString().Equals("configure:object_types")) { foreach (JObject obj in myJson["message"]) { //engine.AddTextToLog(obj["name"] + " " + obj["width"] + " " + obj["height"]); engine.GetObjectManager().AddObjectType(obj["name"].ToString(), int.Parse(obj["width"].ToString()), int.Parse(obj["height"].ToString())); } } else if (myJson["type"].ToString().Equals("configure:objects")) { foreach (JObject obj in myJson["message"]) { //engine.AddTextToLog(obj["name"] + " " + obj["width"] + " " + obj["height"]); string type = obj["type"].ToString(); if (engine.GetObjectManager().ExistsObjectType(type)) { ObjectType objType = engine.GetObjectManager().GetObjectTypes()[type]; engine.GetObjectManager().AddPossibleObject(new SingleObject(type, obj["name"].ToString(), objType.GetWidth(), objType.GetHeight())); } else { // error: nie ma takiego typu } } } else if (myJson["type"].ToString().Equals("configure:sizing")) { int height = int.Parse(myJson["message"]["height"].ToString()); int width = int.Parse(myJson["message"]["width"].ToString()); int gutter = int.Parse(myJson["message"]["gutter"].ToString()); engine.GetCalibrator().SetScreenHeight(height); engine.GetCalibrator().SetScreenWidth(width); } myJson["type"] = myJson["type"].ToString().Replace("configure:", "reconfigured:"); } else if (myJson["type"].ToString().Equals("calibration:listen_to_start")) { /*send(SpeechRecognizer.Orders.CALIBRATE); //tylko dla mockowania, do usuniecia jak bedzie kinect, on wysle sygnal po rozpoznaniu slowa * while (count < markers.Length) * { * send(SpeechRecognizer.Orders.MARK); //tylko dla mockowania, do usuniecia jak bedzie kinect, on wysle sygnal po rozpoznaniu slowa * } * * send(SpeechRecognizer.Orders.DONE); * return;*/ engine.GetSpeechRecognizer().CreateAndLoadGrammarWithObjectsNames(engine.GetObjectManager().GetPossibleObjectsNames()); } else if (myJson["type"].ToString().Equals("work:init")) { send(SpeechRecognizer.Orders.WORK); if (engine.SetAppStateToWorking()) { engine.AddTextToLog("Aplikacja w pelni gotowa do dzialania!"); } else { engine.AddTextToLog("Wystapil blad przy aktywacji aplikacji! Zresetuj program!"); } return; } else if (myJson["type"].ToString().Equals("object:set_active")) { engine.GetObjectManager().SelectObject(myJson["message"]["name"].ToString()); return; } if (_name.IsEmpty()) { msg = myJson.ToString(); } else { msg = String.Format("{0}: {1}", _name, myJson.ToString()); } if (engine != null) { //engine.AddTextToLog(msg); } Broadcast(msg); System.Diagnostics.Debug.WriteLine("aaa"); }