private IEnumerator ProcessSpeechInput(SpeechInputEventArgs inputData) { Context context = ContextManager.Instance.SafeContext; var eventArgs = new SpeechInteractionEventArgs(inputData); if (eventArgs.Keyword == Interaction.KeywordType.None) { yield break; } eventArgs.Selected = context.Selected; eventArgs.Focused = context.Focused; Command command = new Command(eventArgs); if (AppConfig.SharingEnabled && AppConfig.IsServerInstance) { string sendCommand = ParseSpeechCommand(command, eventArgs); SendCommandToRemote(sendCommand); } if (CurrentState != null) { yield return(CurrentState.ProcessCommand(eventArgs, command)); } yield break; }
public void InvokeSpeechInputEvent(Action <SpeechInputEventArgs> action, SpeechInputEventArgs eventArgs) { // If input event is valid, invoke. if (ValidateInputEvent(eventArgs)) { action.Invoke(eventArgs); } }
public SpeechInteractionEventArgs(SpeechInputEventArgs eventArgs) { Data = eventArgs.Data; Input = eventArgs.Input; string keywordString = eventArgs.Keyword.ToString(); Keyword = (KeywordType)Enum.Parse(typeof(KeywordType), keywordString, true); }
public IEnumerator SendRequest(SpeechInputEventArgs eventArgs) { if (AppConfig.SharingEnabled && !AppConfig.IsServerInstance) { yield break; } Context context = ContextManager.Instance.SafeContext; string focused = context.Focused.name; string selected = context.Selected.name; string focusedType = context.SelectedType.ToString(); string selectedType = context.SelectedType.ToString(); string gesture = ""; NLUServiceContext nluContext = new NLUServiceContext(focused, focusedType, selected, selectedType, gesture); yield return(FetchData(eventArgs.Input, nluContext)); if (!_errorState) { string response = _latestResponse; JSONObject jsonObject = new JSONObject(response); var intent = jsonObject.GetField("intent_name").GetField("name").ToString(); intent = char.ToLower(intent[1]) + intent.Substring(2, intent.Length - 3); if (_intentToKeyword.ContainsKey(intent)) { eventArgs.Keyword = _intentToKeyword[intent]; } else { eventArgs.Keyword = KeywordType.None; } eventArgs.Data = jsonObject.GetField("data").ToString(); } yield return(null); }
private bool ValidateInputEvent(SpeechInputEventArgs eventArgs) { return(AppConfig.IsServerInstance || !SyncManager.SharingStarted); }
public void OnSpeechInputEvent(SpeechInputEventArgs inputData) => StartCoroutine(ProcessSpeechInput(inputData));