Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private const string ON = "enabled";
- private const string OFF = "disabled";
- private SpeechRecognizer speechRecognizer;
- private CoreDispatcher dispatcher;
- private StringBuilder dictateBuilder;
- public NotesPage() {
- InitializeComponent();
- dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
- speechRecognizer = new SpeechRecognizer();
- dictateBuilder = new StringBuilder();
- }
- case "0":
- var dictationConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "dictation");
- speechRecognizer.Constraints.Add(dictationConstraint);
- SpeechRecognitionCompilationResult result = await speechRecognizer.CompileConstraintsAsync();
- speechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_CompletedAsync;
- speechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;
- speechRecognizer.HypothesisGenerated += SpeechRecognizer_HypothesisGenerated;
- await speechRecognizer.ContinuousRecognitionSession.StartAsync();
- textToSpeech.Background = (SolidColorBrush)Resources[ON];
- 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 async void ContinuousRecognitionSession_CompletedAsync(
- SpeechContinuousRecognitionSession sender,
- SpeechContinuousRecognitionCompletedEventArgs args) {
- await speechRecognizer.ContinuousRecognitionSession.StopAsync();
- speechRecognizer.Dispose();
- textToSpeech.Background = (SolidColorBrush)Resources[OFF];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement