Esempio n. 1
0
        /// <summary>
        /// Set the UI based on the current state of the speech state machine
        /// </summary>
        /// <param name="state"></param>
        private void SpeechSetUIState(SpeechHelper.SpeechState state)
        {
            switch (state)
            {
            case SpeechHelper.SpeechState.Initializing:
                SpeechLabelText        = "initializing...";
                SpeechButtonText       = "done";
                SpeechButtonEnabled    = false;
                SpeechCancelButtonText = "cancel";
                break;

            case SpeechHelper.SpeechState.Listening:
                SpeechLabelText        = "listening...";
                SpeechButtonText       = "done";
                SpeechButtonEnabled    = true;
                SpeechCancelButtonText = "cancel";
                break;

            case SpeechHelper.SpeechState.Recognizing:
                SpeechLabelText        = "recognizing...";
                SpeechButtonText       = "try again";
                SpeechButtonEnabled    = false;
                SpeechCancelButtonText = "cancel";
                break;

            case SpeechHelper.SpeechState.Finished:
                SpeechLabelText        = "";
                SpeechButtonText       = "try again";
                SpeechButtonEnabled    = true;
                SpeechCancelButtonText = "ok";
                break;
            }
        }
Esempio n. 2
0
        // handle events associated with the Speech Popup
        private void SpeechButton_Click(object sender, RoutedEventArgs 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("ListPage: Navigate to Settings");

                // Navigate to the settings page
                NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
                return;
            }

            // set the UI state to initializing state
            speechState = SpeechHelper.SpeechState.Initializing;
            SpeechSetUIState(speechState);

            // store debug / timing info
            speechStart       = DateTime.Now;
            speechDebugString = "";

            // store debug / timing info
            TimeSpan ts          = DateTime.Now - speechStart;
            string   stateString = SpeechHelper.SpeechStateString(speechState);
            string   traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, "Connecting Socket");

            TraceHelper.AddMessage(traceString);
            speechDebugString += traceString + "\n";

            // initialize the connection to the speech service
            SpeechHelper.Start(
                App.ViewModel.User,
                new SpeechHelper.SpeechStateCallbackDelegate(SpeechPopup_SpeechStateCallback),
                new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack));

            // open the popup
            SpeechPopup.IsOpen = true;
        }
Esempio n. 3
0
        private void SpeechPopup_SpeechStateCallback(SpeechHelper.SpeechState state, string message)
        {
            speechState = state;
            SpeechSetUIState(speechState);

            // store debug / timing info
            TimeSpan ts          = DateTime.Now - speechStart;
            string   stateString = SpeechHelper.SpeechStateString(state);
            string   traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, message);

            TraceHelper.AddMessage(traceString);
            speechDebugString += traceString + "\n";
        }
Esempio n. 4
0
        private void SpeechPopup_SpeechToTextCallback(string textString)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // set the UI state to finished state
                speechState = SpeechHelper.SpeechState.Finished;
                SpeechSetUIState(speechState);

                // store debug / timing info
                TimeSpan ts        = DateTime.Now - speechStart;
                string stateString = SpeechHelper.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);
                QuickAddPopupTextBox.Text = textString;

#if DEBUG && KILL
                MessageBox.Show(speechDebugString);
#endif
            });
        }
Esempio n. 5
0
        private void SpeechPopup_SpeechToTextCallback(string textString)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // set the UI state to finished state
                speechState = SpeechHelper.SpeechState.Finished;
                SpeechSetUIState(speechState);

                // store debug / timing info
                TimeSpan ts = DateTime.Now - speechStart;
                string stateString = SpeechHelper.SpeechStateString(speechState);
                speechDebugString += String.Format("New state: {0}; Time: {1}; Message: {2}\n", stateString, ts.TotalSeconds, textString);

                // 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);
                PopupTextBox.Text = textString;

            #if DEBUG && KILL
                MessageBox.Show(speechDebugString);
            #endif
            });
        }
Esempio n. 6
0
        private void SpeechPopup_SpeechStateCallback(SpeechHelper.SpeechState state, string message)
        {
            speechState = state;
            SpeechSetUIState(speechState);

            // store debug / timing info
            TimeSpan ts = DateTime.Now - speechStart;
            string stateString = SpeechHelper.SpeechStateString(state);
            speechDebugString += String.Format("New state: {0}; Time: {1}; Message: {2}\n", stateString, ts.TotalSeconds, message);
        }
Esempio n. 7
0
        private void SpeechPopup_SpeakButton_Click(object sender, RoutedEventArgs e)
        {
            TimeSpan ts;
            string stateString;

            switch (speechState)
            {
                case SpeechHelper.SpeechState.Initializing:
                    // can't happen since the button isn't enabled
            #if DEBUG
                    MessageBox.Show("Invalid state SpeechState.Initializing reached");
            #endif
                    break;
                case SpeechHelper.SpeechState.Listening:
                    // done button tapped

                    // set the UI state to recognizing state
                    speechState = SpeechHelper.SpeechState.Recognizing;
                    SpeechSetUIState(speechState);

                    // store debug / timing info
                    ts = DateTime.Now - speechStart;
                    stateString = SpeechHelper.SpeechStateString(speechState);
                    speechDebugString += String.Format("New state: {0}; Time: {1}; Message: {2}\n", stateString, ts.TotalSeconds, "Stopping mic");

                    // stop listening and get the recognized text from the speech service
                    //SpeechHelper.Stop(
                    //    App.ViewModel.User,
                    //    new SpeechHelper.SpeechToTextCallbackDelegate(SpeechPopup_SpeechToTextCallback),
                    //    new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack));
                    SpeechHelper.Stop(new SpeechHelper.SpeechToTextCallbackDelegate(SpeechPopup_SpeechToTextCallback));
                    break;
                case SpeechHelper.SpeechState.Recognizing:
                    // can't happen since the button isn't enabled
            #if DEBUG
                    MessageBox.Show("Invalid state SpeechState.Initializing reached");
            #endif
                    break;
                case SpeechHelper.SpeechState.Finished:
                    // "try again" button tapped

                    // set the UI state to initializing state
                    speechState = SpeechHelper.SpeechState.Initializing;
                    SpeechSetUIState(speechState);

                    // store debug / timing info
                    speechStart = DateTime.Now;
                    speechDebugString = "";

                    // store debug / timing info
                    ts = DateTime.Now - speechStart;
                    stateString = SpeechHelper.SpeechStateString(speechState);
                    speechDebugString += String.Format("New state: {0}; Time: {1}; Message: {2}\n", stateString, ts.TotalSeconds, "Initializing Request");

                    // initialize the connection to the speech service
                    SpeechHelper.Start(
                        App.ViewModel.User,
                        new SpeechHelper.SpeechStateCallbackDelegate(SpeechPopup_SpeechStateCallback),
                        new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack));
                    break;
            }
        }
Esempio n. 8
0
        // handle events associated with the Speech Popup
        private void SpeechButton_Click(object sender, RoutedEventArgs e)
        {
            // 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("TaskList: Navigate to Settings");

                // Navigate to the settings page
                NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
                return;
            }

            // set the UI state to initializing state
            speechState = SpeechHelper.SpeechState.Initializing;
            SpeechSetUIState(speechState);

            // store debug / timing info
            speechStart = DateTime.Now;
            speechDebugString = "";

            // store debug / timing info
            TimeSpan ts = DateTime.Now - speechStart;
            string stateString = SpeechHelper.SpeechStateString(speechState);
            speechDebugString += String.Format("New state: {0}; Time: {1}; Message: {2}\n", stateString, ts.TotalSeconds, "Connecting Socket");

            // initialize the connection to the speech service
            SpeechHelper.Start(
                App.ViewModel.User,
                new SpeechHelper.SpeechStateCallbackDelegate(SpeechPopup_SpeechStateCallback),
                new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack));

            // open the popup
            SpeechPopup.IsOpen = true;
        }
Esempio n. 9
0
        // handle events associated with the Speech Popup
        private void SpeechButton_Click(object sender, RoutedEventArgs 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("ListPage: Navigate to Settings");

                // Navigate to the settings page
                NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
                return;
            }

            // initialize the Speech provider
            #if DEBUG
            SpeechHelper.SpeechProvider = SpeechHelper.SpeechProviders.NativeSpeech;
            #endif

            // set the UI state to initializing state
            speechState = SpeechHelper.SpeechState.Initializing;
            SpeechSetUIState(speechState);

            // store debug / timing info
            speechStart = DateTime.Now;
            speechDebugString = "";

            // store debug / timing info
            TimeSpan ts = DateTime.Now - speechStart;
            string stateString = SpeechHelper.SpeechStateString(speechState);
            string traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, "Connecting Socket");
            TraceHelper.AddMessage(traceString);
            speechDebugString += traceString + "\n";

            // initialize the connection to the speech service
            SpeechHelper.Start(
                App.ViewModel.User,
                new SpeechHelper.SpeechStateCallbackDelegate(SpeechPopup_SpeechStateCallback),
                new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack));

            // open the popup
            SpeechPopup.IsOpen = true;
        }
Esempio n. 10
0
        private void SpeechPopup_SpeakButton_Click(object sender, RoutedEventArgs e)
        {
            TimeSpan ts;
            string   stateString;
            string   traceString;

            switch (speechState)
            {
            case SpeechHelper.SpeechState.Initializing:
                // can't happen since the button isn't enabled
#if DEBUG
                MessageBox.Show("Invalid state SpeechState.Initializing reached");
#endif
                break;

            case SpeechHelper.SpeechState.Listening:
                // done button tapped

                // set the UI state to recognizing state
                speechState = SpeechHelper.SpeechState.Recognizing;
                SpeechSetUIState(speechState);

                // store debug / timing info
                ts          = DateTime.Now - speechStart;
                stateString = SpeechHelper.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
                SpeechHelper.Stop(new SpeechHelper.SpeechToTextCallbackDelegate(SpeechPopup_SpeechToTextCallback));
                break;

            case SpeechHelper.SpeechState.Recognizing:
                // can't happen since the button isn't enabled
#if DEBUG
                MessageBox.Show("Invalid state SpeechState.Initializing reached");
#endif
                break;

            case SpeechHelper.SpeechState.Finished:
                // "try again" button tapped

                // set the UI state to initializing state
                speechState = SpeechHelper.SpeechState.Initializing;
                SpeechSetUIState(speechState);

                // store debug / timing info
                speechStart       = DateTime.Now;
                speechDebugString = "";

                // store debug / timing info
                ts          = DateTime.Now - speechStart;
                stateString = SpeechHelper.SpeechStateString(speechState);
                traceString = String.Format("New state: {0}; Time: {1}; Message: {2}", stateString, ts.TotalSeconds, "Initializing Request");
                TraceHelper.AddMessage(traceString);
                speechDebugString += traceString + "\n";

                // initialize the connection to the speech service
                SpeechHelper.Start(
                    App.ViewModel.User,
                    new SpeechHelper.SpeechStateCallbackDelegate(SpeechPopup_SpeechStateCallback),
                    new MainViewModel.NetworkOperationInProgressCallbackDelegate(SpeechPopup_NetworkOperationInProgressCallBack));
                break;
            }
        }