Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isListening == false) {
- // The recognizer can only start listening in a continuous fashion if the recognizer is currently idle.
- // This prevents an exception from occurring.
- if (speechRecognizer.State == SpeechRecognizerState.Idle) {
- isListening = true;
- await speechRecognizer.ContinuousRecognitionSession.StartAsync();
- isListening = false;
- }
- } else {
- isListening = false;
- if (speechRecognizer.State != SpeechRecognizerState.Idle) {
- // Cancelling recognition prevents any currently recognized speech from
- // generating a ResultGenerated event. StopAsync() will allow the final session to
- // complete.
- await speechRecognizer.ContinuousRecognitionSession.StopAsync();
- }
- }
- break;
- case "1":
- if (richEbitBox.Document.Selection.CharacterFormat.Bold == FormatEffect.On) {
- richEbitBox.Document.Selection.CharacterFormat.Bold = FormatEffect.Off;
- FormatBoltText.Background = (SolidColorBrush)Resources[OFF];
- } else {
- richEbitBox.Document.Selection.CharacterFormat.Bold = FormatEffect.On;
- FormatBoltText.Background = (SolidColorBrush)Resources[ON];
- }
- break;
- case "2":
- if (richEbitBox.Document.Selection.CharacterFormat.Italic == FormatEffect.On) {
- richEbitBox.Document.Selection.CharacterFormat.Italic = FormatEffect.Off;
- formatItalicText.Background = (SolidColorBrush)Resources[OFF];
- } else {
- richEbitBox.Document.Selection.CharacterFormat.Italic = FormatEffect.On;
- formatItalicText.Background = (SolidColorBrush)Resources[ON];
- }
- break;
- case "3":
- if (richEbitBox.Document.Selection.CharacterFormat.Underline == UnderlineType.Single) {
- richEbitBox.Document.Selection.CharacterFormat.Underline = UnderlineType.None;
- formatUnderlineText.Background = (SolidColorBrush)Resources[OFF];
- } else {
- richEbitBox.Document.Selection.CharacterFormat.Underline = UnderlineType.Single;
- formatUnderlineText.Background = (SolidColorBrush)Resources[ON];
- }
- break;
- case "5":
- richEbitBox.Document.GetText(TextGetOptions.AdjustCrlf, out string value);
- speak(value);
- break;
- default:
- break;
- }
- }
- private async void SpeechRecognizer_HypothesisGenerated(
- SpeechRecognizer sender,
- SpeechRecognitionHypothesisGeneratedEventArgs args) {
- string hypothesis = args.Hypothesis.Text;
- string textboxContent = dictateBuilder.ToString() + " " + hypothesis + " ...";
- await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
- richEbitBox.Document.SetText(TextSetOptions.None, textboxContent);
- });
- }
- private async void ContinuousRecognitionSession_ResultGenerated(
- SpeechContinuousRecognitionSession sender,
- SpeechContinuousRecognitionResultGeneratedEventArgs args) {
- if (args.Result.Confidence == SpeechRecognitionConfidence.Medium ||
- args.Result.Confidence == SpeechRecognitionConfidence.High) {
- dictateBuilder.Append(args.Result.Text + " ");
- await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
- richEbitBox.Document.SetText(TextSetOptions.None, dictateBuilder.ToString());
- });
- }
- }
- private void ContinuousRecognitionSession_Completed(
- SpeechContinuousRecognitionSession sender,
- SpeechContinuousRecognitionCompletedEventArgs args) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement