protected virtual void OnHaveResultEvent(SpeechToTextEventArgs e)
 {
     SpeechToTextEventHandler handler = HaveResult;
     if (handler != null)
     {
         handler(this, e);
     }
 }
 protected virtual void OnStopEvent(SpeechToTextEventArgs e)
 {
     SpeechToTextEventHandler handler = Stop;
     if (handler != null)
     {
         handler(this, e);
     }
 }
 public async void StopRecognization()
 {
     if (speechRecognizer.State != SpeechRecognizerState.Idle)
     {
         await speechRecognizer.ContinuousRecognitionSession.CancelAsync();
     }
     OnStopEvent(speechToTextEventArgs);
     speechToTextEventArgs = new SpeechToTextEventArgs();
 }
        /// <summary>
        /// Event handler function for <see cref="SpeechToText"/> client updates
        /// Displays all results in the UI, and calls LUIS if a complete sentence have been converted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSttStatusUpdated(object sender, SpeechToTextEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                StringBuilder sb = new StringBuilder();

                if (e.Status == SttStatus.Success)
                {
                    if (!string.IsNullOrEmpty(e.Message))
                    {
                        sb.AppendFormat("Result message: {0}\n\n", e.Message);
                    }

                    if (e.Results != null && e.Results.Count != 0)
                    {
                        sb.Append("Retrieved the following results:\n");
                        foreach (string sentence in e.Results)
                        {
                            sb.AppendFormat("{0}\n\n", sentence);
                        }

                        sb.Append("Calling LUIS with the top result\n");

                        CallLuis(e.Results.FirstOrDefault());
                    }
                }
                else
                {
                    sb.AppendFormat("Could not convert speech to text: {0}\n", e.Message);
                }

                sb.Append("\n");

                ResultText = sb.ToString();
            });
        }
 private SpeechToText()
 {
     speechToTextEventArgs = new SpeechToTextEventArgs();
 }