private static DemoMethodType AnalysisFunctionPrototype(string funcStr) { string[] strSplit = funcStr.Split(' '); DemoMethodType method = new DemoMethodType(); method.methodName = strSplit [0]; method.paras = new string[strSplit.Length - 1]; for (int i = 1; i < strSplit.Length; i++) { method.paras [i - 1] = strSplit [i]; } return(method); }
static private void OnASREvent(object source, ElapsedEventArgs e) { ASRTimer.Stop(); String[] locations = new String[3] { "nearest", "closest", "farthest" }; KaldiClient.Send("ASREvent speech request"); String replyString = KaldiClient.Receive(); System.Console.WriteLine(replyString); if (!replyString.Equals("---NO SPEECH---")) { String[] reply = replyString.Split('\t'); //string, parse, dependencies List <String[]> dep = new List <String[]> (); //[['advmod', 'is', 'where'], ['root', 'ROOT', 'is'], ['det', 'tree', 'the'], ['amod', 'tree', 'nearest'], ['nsubj', 'is', 'tree']] String outer = reply [2].Substring(1, reply [2].Length - 2); String[] outerList = outer.Split(new String[] { "], [" }, StringSplitOptions.None); outerList [0] = outerList [0].Substring(1); outerList [outerList.Length - 1] = outerList [outerList.Length - 1].Substring(0, outerList [outerList.Length - 1].Length - 1); // remove nonsense characters foreach (String s in outerList) { String[] inner = s.Split(','); for (int i = 0; i < inner.Length; i++) { inner [i] = inner [i].Replace("'", ""); // remove " ' " inner [i] = inner [i].Replace(" ", ""); // remove space before each word } dep.Add(inner); } String cmdFiltered = FilterCmd(dep); if (keyWordToCmdMap.ContainsKey(cmdFiltered)) { string funcStr = keyWordToCmdMap [cmdFiltered].ToString(); DemoMethodType methodInfo = AnalysisFunctionPrototype(funcStr); Type type = typeof(Program); string methodName = methodInfo.methodName; string[] paras = methodInfo.paras; MethodInfo info = type.GetMethod(methodName); info.Invoke(null, new object[] { paras }); } } else { System.Console.WriteLine("NO SPEECH"); } ASRTimer.Start(); }