Advertisement
eduardogr

Untitled

Dec 25th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.42 KB | None | 0 0
  1.  if (isListening == false) {
  2.                         // The recognizer can only start listening in a continuous fashion if the recognizer is currently idle.
  3.                         // This prevents an exception from occurring.
  4.                         if (speechRecognizer.State == SpeechRecognizerState.Idle) {
  5.                             isListening = true;
  6.                             await speechRecognizer.ContinuousRecognitionSession.StartAsync();
  7.                             isListening = false;
  8.                         }
  9.                     } else {
  10.                         isListening = false;
  11.                         if (speechRecognizer.State != SpeechRecognizerState.Idle) {
  12.                             // Cancelling recognition prevents any currently recognized speech from
  13.                             // generating a ResultGenerated event. StopAsync() will allow the final session to
  14.                             // complete.
  15.                             await speechRecognizer.ContinuousRecognitionSession.StopAsync();
  16.                         }
  17.                     }
  18.                     break;
  19.                 case "1":
  20.                     if (richEbitBox.Document.Selection.CharacterFormat.Bold == FormatEffect.On) {
  21.                         richEbitBox.Document.Selection.CharacterFormat.Bold = FormatEffect.Off;
  22.                         FormatBoltText.Background = (SolidColorBrush)Resources[OFF];
  23.                     } else {
  24.                         richEbitBox.Document.Selection.CharacterFormat.Bold = FormatEffect.On;
  25.                         FormatBoltText.Background = (SolidColorBrush)Resources[ON];
  26.                     }
  27.                     break;
  28.                 case "2":
  29.                     if (richEbitBox.Document.Selection.CharacterFormat.Italic == FormatEffect.On) {
  30.                         richEbitBox.Document.Selection.CharacterFormat.Italic = FormatEffect.Off;
  31.                         formatItalicText.Background = (SolidColorBrush)Resources[OFF];
  32.                     } else {
  33.                         richEbitBox.Document.Selection.CharacterFormat.Italic = FormatEffect.On;
  34.                         formatItalicText.Background = (SolidColorBrush)Resources[ON];
  35.                     }
  36.                     break;
  37.                 case "3":
  38.                     if (richEbitBox.Document.Selection.CharacterFormat.Underline == UnderlineType.Single) {
  39.                         richEbitBox.Document.Selection.CharacterFormat.Underline = UnderlineType.None;
  40.                         formatUnderlineText.Background = (SolidColorBrush)Resources[OFF];
  41.                     } else {
  42.                         richEbitBox.Document.Selection.CharacterFormat.Underline = UnderlineType.Single;
  43.                         formatUnderlineText.Background = (SolidColorBrush)Resources[ON];
  44.                     }
  45.                     break;
  46.                 case "5":
  47.                     richEbitBox.Document.GetText(TextGetOptions.AdjustCrlf, out string value);
  48.                     speak(value);
  49.                     break;
  50.                 default:
  51.                     break;
  52.             }
  53.         }
  54.  
  55.         private async void SpeechRecognizer_HypothesisGenerated(
  56.             SpeechRecognizer sender,
  57.             SpeechRecognitionHypothesisGeneratedEventArgs args) {
  58.  
  59.             string hypothesis = args.Hypothesis.Text;
  60.             string textboxContent = dictateBuilder.ToString() + " " + hypothesis + " ...";
  61.  
  62.             await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
  63.                 richEbitBox.Document.SetText(TextSetOptions.None, textboxContent);
  64.             });
  65.         }
  66.  
  67.         private async void ContinuousRecognitionSession_ResultGenerated(
  68.             SpeechContinuousRecognitionSession sender,
  69.             SpeechContinuousRecognitionResultGeneratedEventArgs args) {
  70.  
  71.             if (args.Result.Confidence == SpeechRecognitionConfidence.Medium ||
  72.                   args.Result.Confidence == SpeechRecognitionConfidence.High) {
  73.  
  74.                 dictateBuilder.Append(args.Result.Text + " ");
  75.  
  76.                 await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
  77.                     richEbitBox.Document.SetText(TextSetOptions.None, dictateBuilder.ToString());
  78.                 });
  79.             }
  80.         }
  81.  
  82.         private void ContinuousRecognitionSession_Completed(
  83.             SpeechContinuousRecognitionSession sender,
  84.             SpeechContinuousRecognitionCompletedEventArgs args) {
  85.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement