// Process all events private void Process() { // check if controller has any new input SpeechControllerState currentState = SpeechControllerInput.shared.currentState; string recognizedText = currentState.recognizedSpeech; // check if we can use this text if (currentState.errorCode == SCErrorCode.no_error && recognizedText.Length > 0) { SpeechTextType textType = SpeechTextType.error; // send input to actors for handling bool eventIsHandled = false; // call all the handlers to handle the event foreach (ISpeechEventActionResponder aResponder in responders) { eventIsHandled = eventIsHandled || aResponder.handleEvent(recognizedText); } if (eventIsHandled) { textType = SpeechTextType.valid; controllerShouldBeActive = false; } // send output to display outputReceiver.logEvent(recognizedText, textType); } // check if controller needs to be started or stopped if (controllerShouldBeActive) { SpeechControllerInput.shared.controllerStart(); outputReceiver.appear(); } else { SpeechControllerInput.shared.controllerStop(); outputReceiver.disappear(); } }
// Event processor interface public void logEvent(string text, SpeechTextType type) { Text speech = GameObject.Find("Speech").GetComponent <UnityEngine.UI.Text>(); // show text speech.text = text; // add color based on type switch (type) { case SpeechTextType.system: speech.color = Color.white; break; case SpeechTextType.valid: speech.color = Color.green; break; case SpeechTextType.error: speech.color = Color.red; break; } }