private void SpeechPopup_CancelButton_Click(object sender, EventArgs e) { switch (speechState) { case NuanceHelper.SpeechState.Initializing: case NuanceHelper.SpeechState.Listening: case NuanceHelper.SpeechState.Recognizing: // user tapped the cancel button // cancel the current operation / close the socket to the service NuanceHelper.Cancel( new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack)); // reset the text in the textbox //parent.Name.Value = ""; parent.SpeechTextLabel.Text = ""; break; case NuanceHelper.SpeechState.Finished: // user tapped the OK button // set the text in the popup textbox //parent.Name.Value = SpeechLabelText.Trim('\''); //parent.Name.Value = ""; break; } SpeechPopup_Close(); }
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 override void ViewDidDisappear(bool animated) { TraceHelper.AddMessage("Add: ViewDidDisappear"); dialogViewController.ReloadComplete(); App.ViewModel.SyncComplete -= RefreshHandler; App.ViewModel.SyncCompleteArg = null; NuanceHelper.Cleanup(); // force the soft keyboard to dismiss dialogViewController.TableView.EndEditing(true); base.ViewDidDisappear(animated); }
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; } }
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 }); }
public override void Canceled(UIActionSheet actionSheet) { // cancel the current operation / close the socket to the service NuanceHelper.Cancel( new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack)); }
// handle events associated with the Speech Popup private void SpeechButton_Click(object sender, EventArgs e) { // require a connection // if (DeviceNetworkInformation.IsNetworkAvailable == false || // NetworkInterface.GetIsNetworkAvailable() == false) // { // MessageBox.Show("apologies - a network connection is required for this feature, and you appear to be disconnected :-("); // return; // } // require an account if (App.ViewModel.User == null) { MessageBoxResult result = MessageBox.Show( "the speech feature requires an account. create a free account now?", "create account?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } // trace page navigation TraceHelper.StartMessage("Add: Navigate to Settings"); // Navigate to the settings page this.TabBarController.PresentViewController(this.TabBarController.ViewControllers[3], true, null); return; } // initialize the speech popup delegate SpeechPopupDelegate.parent = this; SpeechPopupDelegate.speechState = NuanceHelper.SpeechState.Initializing; // store debug / timing info SpeechPopupDelegate.speechStart = DateTime.Now; SpeechPopupDelegate.speechDebugString = ""; // store debug / timing info TimeSpan ts = DateTime.Now - SpeechPopupDelegate.speechStart; string stateString = NuanceHelper.SpeechStateString(SpeechPopupDelegate.speechState); string traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, "Connecting Socket"); TraceHelper.AddMessage(traceString); SpeechPopupDelegate.speechDebugString += traceString + "\n"; // cancel any existing speech operation NuanceHelper.Cleanup(); // initialize the connection to the speech service NuanceHelper.Start( App.ViewModel.User, new NuanceHelper.SpeechToTextCallbackDelegate(SpeechPopupDelegate.SpeechPopup_SpeechToTextCallback), new NuanceHelper.SpeechStateCallbackDelegate(SpeechPopupDelegate.SpeechPopup_SpeechStateCallback), new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopupDelegate.SpeechPopup_NetworkOperationInProgressCallBack)); if (SpeechPopupDelegate.speechState == NuanceHelper.SpeechState.Initializing) { // open the popup SetupSpeechPopup("initializing..."); SpeechPopup.ShowFromTabBar(((UITabBarController)this.ParentViewController).TabBar); } else { MessageBox.Show("our apologies - speech is unavailable at this time."); } }