/// <summary> /// Set the UI based on the current state of the speech state machine /// </summary> /// <param name="state"></param> private void SpeechSetUIState(NuanceHelper.SpeechState state) { switch (state) { case NuanceHelper.SpeechState.Initializing: //parent.SpeechPopup.Title = "initializing..."; parent.SpeechTextLabel.Text = "initializing..."; break; case NuanceHelper.SpeechState.Listening: //parent.SpeechPopup.Title = "listening..."; parent.SpeechTextLabel.Text = "listening..."; break; case NuanceHelper.SpeechState.Recognizing: //parent.SpeechPopup.Title = "recognizing..."; //parent.ActivityIndicator.Hidden = false; parent.SpeechTextLabel.Text = "recognizing..."; break; case NuanceHelper.SpeechState.Finished: //parent.SpeechPopup.Title = ""; parent.SpeechTextLabel.Text = ""; break; } // resize and recenter the label parent.SpeechTextLabel.SizeToFit(); parent.SpeechTextLabel.Center = new PointF(parent.View.Center.X, parent.ActivityIndicator.Center.Y); }
public void SpeechPopup_SpeechStateCallback(NuanceHelper.SpeechState state, string message) { speechState = state; SpeechSetUIState(speechState); // store debug / timing info TimeSpan ts = DateTime.Now - speechStart; string stateString = NuanceHelper.SpeechStateString(state); string traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, message); TraceHelper.AddMessage(traceString); speechDebugString += traceString + "\n"; }
public void SpeechPopup_SpeechToTextCallback(string textString) { parent.BeginInvokeOnMainThread(() => { // set the UI state to finished state speechState = NuanceHelper.SpeechState.Finished; SpeechSetUIState(speechState); // store debug / timing info TimeSpan ts = DateTime.Now - speechStart; string stateString = NuanceHelper.SpeechStateString(speechState); string traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, textString); TraceHelper.AddMessage(traceString); speechDebugString += traceString + "\n"; // strip any timing / debug info textString = textString == null ? "" : textString; string[] words = textString.Split(' '); if (words[words.Length - 1] == "seconds") { textString = ""; // strip off last two words - "a.b seconds" for (int i = 0; i < words.Length - 2; i++) { textString += words[i]; textString += " "; } textString = textString.Trim(); } // set the speech label text as well as the popup text //SpeechLabelText = textString == null ? "recognition failed" : String.Format("'{0}'", textString); parent.Name.Value = textString; // dismiss the SpeechPopup parent.SpeechPopup.DismissWithClickedButtonIndex(1, true); #if DEBUG && KILL MessageBox.Show(speechDebugString); #endif }); }
private void SpeechPopup_SpeakButton_Click(object sender, EventArgs e) { TimeSpan ts; string stateString; string traceString; switch (speechState) { case NuanceHelper.SpeechState.Initializing: // can't happen since the button isn't enabled #if DEBUG //MessageBox.Show("Invalid state SpeechState.Initializing reached"); #endif //break; case NuanceHelper.SpeechState.Listening: // done button tapped // set the UI state to recognizing state speechState = NuanceHelper.SpeechState.Recognizing; SpeechSetUIState(speechState); // store debug / timing info ts = DateTime.Now - speechStart; stateString = NuanceHelper.SpeechStateString(speechState); traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, "Stopping mic"); TraceHelper.AddMessage(traceString); speechDebugString += traceString + "\n"; // stop listening and get the recognized text from the speech service NuanceHelper.Stop(); // put the SpeechPopup back up to show the recognition phase parent.SetupSpeechPopup("recognizing..."); parent.SpeechPopup.ShowFromTabBar(((UITabBarController)parent.ParentViewController).TabBar); break; case NuanceHelper.SpeechState.Recognizing: // clicking done while recognizing means cancel the operation parent.SpeechPopup.DismissWithClickedButtonIndex(1, true); break; case NuanceHelper.SpeechState.Finished: // should never happen parent.SpeechPopup.DismissWithClickedButtonIndex(1, true); break; } }