use button for dictation

Eduardo Gomez 3,416 Reputation points
2019-11-13T04:26:11.89+00:00
Hello @RoyLiWicresoftNorthAmericaLtd-0833  I am using continues dictation in my app, but I have a problem, even though I put the silence time out to 1 day, it will still timeout after a while.  

What I am trying to do, is that the user press the button and I start speaking, and If I hit the button again it will stop listening. For some reason. I also want the app to type, while I am speaking

     case "0":  
                    dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;  
                    speechRecognizer = new SpeechRecognizer();  
                    await speechRecognizer.CompileConstraintsAsync();  
                    speechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;  
                    speechRecognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout = TimeSpan.FromDays(1);  
                    speechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;  
                    await speechRecognizer.ContinuousRecognitionSession.StartAsync();  
                    textToSpeech.Background = (SolidColorBrush)Resources[ON];  
                    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 "4":  
                    if (Ink_cnvas.Visibility == Visibility.Collapsed) {  
                        formatDraw.Background = (SolidColorBrush)Resources[ON];  
                        Ink_cnvas.Visibility = Visibility.Visible;  
                        richEbitBox.Visibility = Visibility.Collapsed;  
                    } else if (Ink_cnvas.Visibility == Visibility.Visible) {  
                        Ink_cnvas.Visibility = Visibility.Collapsed;  
                        formatDraw.Background = (SolidColorBrush)Resources[OFF];  
                        richEbitBox.Visibility = Visibility.Visible;  
                    }  
                    break;  
                default:  
                    break;  
            }  
        }  
  
        private async void ContinuousRecognitionSession_Completed(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionCompletedEventArgs args) {  
  
            await speechRecognizer.ContinuousRecognitionSession.StartAsync();  
        }  
  
        private async void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args) {  
  
            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => {  
  
                    richEbitBox.Document.GetText(TextGetOptions.AdjustCrlf, out string value);  
                    richEbitBox.Document.SetText(TextSetOptions.None, value + args.Result.Text);  
                    textToSpeech.Background = (SolidColorBrush)Resources[OFF]; // This will indicate that my button is off  
                    await speechRecognizer.ContinuousRecognitionSession.StopAsync();      
            });  
        }  
  
Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2019-11-19T05:14:24.747+00:00

    Hello,
    For your requirement, you could refer SpeechRecognitionAndSynthesis official code sample, and Scenario_ContinuousDictation could meet your need.