private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args) { System.Action keywordAction; if (keywords.TryGetValue(args.text, out keywordAction)) { keywordAction.Invoke(); } }
private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args) { UnityEvent keywordResponse; // Check to make sure the recognized keyword exists in the methods dictionary, then invoke the corresponding method. if (responses.TryGetValue(args.text, out keywordResponse)) { keywordResponse.Invoke(); } }
static public int constructor(IntPtr l) { try { UnityEngine.Windows.Speech.PhraseRecognizedEventArgs o; o = new UnityEngine.Windows.Speech.PhraseRecognizedEventArgs(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
private void OnPhraseRecognized(PhraseRecognizedEventArgs args) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("{0} ({1}){2}", args.text, args.confidence, Environment.NewLine); builder.AppendFormat("\tTimestamp: {0}{1}", args.phraseStartTime, Environment.NewLine); builder.AppendFormat("\tDuration: {0} seconds{1}", args.phraseDuration.TotalSeconds, Environment.NewLine); wordChain.Add(args.text); Debug.Log(builder.ToString()); if (args.text.Equals("exit", StringComparison.OrdinalIgnoreCase)) { isTyping = false; isScrolling = false; Debug.Log("Flushing chain"); wordChain = new List<string>(); // Flush the chain } else if (isScrolling) { if (args.text.Equals("up", StringComparison.OrdinalIgnoreCase)) { if (dataPointer - (2 * dataInc) <= 0) dataPointer = 0; else dataPointer -= (2 * dataInc); Debug.Log(dataPointer); string message = ""; int counter = 0; for (int i = dataPointer; counter < dataInc && i < dataList.Count; i++) { if (TranslateLetters(dataList[i]) != dataList[i]) { message += dataList[i] + " --> " + TranslateLetters(dataList[i]) + "\n"; } else { message += dataList[i] + "\n"; } dataPointer++; counter++; } WindowTextController.UpdateInfo(message, true); } else if (args.text.Equals("down", StringComparison.OrdinalIgnoreCase)) { Debug.Log(dataPointer); string message = ""; int counter = 0; for (int i = dataPointer; counter < dataInc && i < dataList.Count; i++) { if (TranslateLetters(dataList[i]) != dataList[i]) { message += dataList[i] + " --> " + TranslateLetters(dataList[i]) + "\n"; } else { message += dataList[i] + "\n"; } if (dataPointer < dataList.Count-1) dataPointer++; counter++; } WindowTextController.UpdateInfo(message, true); } } else if (isTyping) { if (args.text.Equals("capitalize", StringComparison.OrdinalIgnoreCase)) { isCapitalized = true; } else if (args.text.Equals("delete", StringComparison.OrdinalIgnoreCase) && textField.text.Length > 0) { textField.text = textField.text.Substring(0, textField.text.Length - 1); } else if (args.text.Equals("back", StringComparison.OrdinalIgnoreCase) && textField.text.Length > 0) { textField.text = textField.text.Substring(0, textField.text.Length - 1); } else if (args.text.Equals("erase", StringComparison.OrdinalIgnoreCase)) { textField.text = ""; } else if (args.text.Equals("grab", StringComparison.OrdinalIgnoreCase)) { if (DataCache.ReadCacheMessage().IndexOf("-") > -1) { textField.text += DatabaseUtilities.VedicDatabase.GetColumnName(DataCache.ReadCacheMessage()); } else textField.text += DatabaseUtilities.VedicDatabase.GetTableName(DataCache.ReadCacheMessage()); } else textField.text += TranslateLetters(args.text); } else if (args.text.Equals("execute", StringComparison.OrdinalIgnoreCase)) { ActivateWordChain(); } else if (args.text.Equals("flush", StringComparison.OrdinalIgnoreCase)) { Debug.Log("Flushing chain"); wordChain = new List<string>(); // Flush the chain } else if (args.text.Equals("teletype", StringComparison.OrdinalIgnoreCase)) { isTyping = true; Debug.Log("Flushing chain"); wordChain = new List<string>(); // Flush the chain } else if (args.text.Equals("scroll", StringComparison.OrdinalIgnoreCase)) { isScrolling = true; Debug.Log("Flushing chain"); wordChain = new List<string>(); // Flush the chain } }
private void PhraseRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args) { Debug.LogFormat("Confidence={0},duration={1},startTime={2},text={3}", args.confidence, args.phraseDuration, args.phraseStartTime,args.text); Dictionary<string, SemanticKeyAndSemanticMeaning> argDictionary = new Dictionary<string, SemanticKeyAndSemanticMeaning>(); string primaryActionKey = null; if (args.semanticMeanings != null) { for (int i = 0; i < args.semanticMeanings.Length; i++) { var semantic = args.semanticMeanings[i]; Debug.LogFormat("semantic meaning key={0} ", semantic.key); if(primaryActionKey == null && semantic.key == PrimaryActionKey && semantic.values.Length > 0) { primaryActionKey = semantic.values[0]; } else if(secondaryKeywordDictionary.ContainsKey(semantic.key)) { var parameter = secondaryKeywordDictionary[semantic.key]; SemanticKeyAndSemanticMeaning combineInfo = new SemanticKeyAndSemanticMeaning() { KeyType = parameter, Meaning = semantic }; for (int k = 0; k < semantic.values.Length; k++) { var val = semantic.values[k]; Debug.LogFormat("semantic value={0} ", val); } argDictionary.Add(semantic.key, combineInfo); } } } if(!string.IsNullOrEmpty(primaryActionKey)) { var meaning = argDictionary[PrimaryActionKey]; SemanticKeyAndResponse keyResponse; // Check to make sure the recognized keyword exists in the methods dictionary, then invoke the corresponding method. if (responses.TryGetValue(primaryActionKey, out keyResponse)) { int eventCount = keyResponse.Response.GetPersistentEventCount(); for(int z=0;z<eventCount; z++) { MonoBehaviour targetBehavior= keyResponse.Response.GetPersistentTarget(z) as MonoBehaviour; var methodName = keyResponse.Response.GetPersistentMethodName(z); if(argDictionary.Count == 0) { targetBehavior.SendMessage(methodName, SendMessageOptions.DontRequireReceiver); } else { if (argDictionary.Count == 1) { object singleArg; foreach(var key in argDictionary.Keys) { var info = argDictionary[key]; if(info.KeyType.IsIEnumerableCollection) { List<object> values = new List<object>(); for (int i = 0; i < info.Meaning.values.Length; i++) { values.Add(Parsing[info.KeyType.ExpectedType](info.Meaning.values[i])); } singleArg = values; } else { singleArg = Parsing[info.KeyType.ExpectedType](info.Meaning.values[0]); } targetBehavior.SendMessage(methodName, singleArg, SendMessageOptions.DontRequireReceiver); } } else { List<Type> typeList = new List<Type>(); List<System.Object> objectList = new List<System.Object>(); if(keyResponse.SemanticKeywordPrecendence.Length >0) { foreach(var key in keyResponse.SemanticKeywordPrecendence) { if(argDictionary.ContainsKey(key)) { object singleArg; var info = argDictionary[key]; if (info.KeyType.IsIEnumerableCollection) { List<object> values = new List<object>(); for (int i = 0; i < info.Meaning.values.Length; i++) { values.Add(Parsing[info.KeyType.ExpectedType](info.Meaning.values[i])); } singleArg = values; } else { singleArg = Parsing[info.KeyType.ExpectedType](info.Meaning.values[0]); } typeList.Add(singleArg.GetType()); objectList.Add(singleArg); } } } System.Type[] typeArray = typeList.ToArray(); System.Object[] parameters = objectList.ToArray(); // get the method assigned in the editor and call it System.Reflection.MethodInfo methodInfo = UnityEventBase.GetValidMethodInfo(targetBehavior, methodName, typeArray); if (methodInfo != null) { methodInfo.Invoke(targetBehavior.gameObject, parameters); } else { Debug.LogWarningFormat("Did not find method {0} on {1}, check parameter configuration.", methodName, targetBehavior.name); } } } } } } }