当前位置: 首页>>代码示例>>C#>>正文


C# SpeechRecognizer.RecognizeWithUIAsync方法代码示例

本文整理汇总了C#中SpeechRecognizer.RecognizeWithUIAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechRecognizer.RecognizeWithUIAsync方法的具体用法?C# SpeechRecognizer.RecognizeWithUIAsync怎么用?C# SpeechRecognizer.RecognizeWithUIAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpeechRecognizer的用法示例。


在下文中一共展示了SpeechRecognizer.RecognizeWithUIAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: answerYN

 async Task<bool> answerYN(string question)
 {
     var language = SpeechRecognizer.SystemSpeechLanguage;
     speakString(question);
     string[] yn = {"Yes", "No"};
     SpeechRecognizer speechRecognizer = new SpeechRecognizer();
     SpeechRecognitionListConstraint list = new SpeechRecognitionListConstraint(yn, "yesOrNo");
     speechRecognizer.Constraints.Add(list);
     await speechRecognizer.CompileConstraintsAsync();
     SpeechRecognitionResult answerResult = await speechRecognizer.RecognizeWithUIAsync();
     if (answerResult.Text == "Yes")
         return true;
     else
         return false;
 }
开发者ID:Madpixel6,项目名称:Niewidomy,代码行数:15,代码来源:SpeechFunctions1.cs

示例2: VoiceInput_Click

        private async void VoiceInput_Click(object sender, RoutedEventArgs e)
        {
            string message = "";
            try
            {
                SpeechRecognizer speechRecognizer = new SpeechRecognizer();
                SpeechRecognitionCompilationResult compilationResult = await speechRecognizer.CompileConstraintsAsync();

                if (compilationResult.Status == SpeechRecognitionResultStatus.Success)
                {
                    var result = await speechRecognizer.RecognizeWithUIAsync();
                    if (result.Confidence == SpeechRecognitionConfidence.Rejected)
                    {
                        message = "语音识别不到";
                    }
                    else
                    {
                        InputText.Text = result.Text;
                    }
                }

            }
            catch (Exception err)
            {
                message = "异常信息:" + err.Message + err.HResult;
            }
            if (message != "")
                await new MessageDialog(message).ShowAsync();
        }
开发者ID:bajinsheng,项目名称:Traveler,代码行数:29,代码来源:New.xaml.cs

示例3: Recognize


//.........这里部分代码省略.........
            if (isRecognizing && recognizer != null)
            {
                await recognizer.StopRecognitionAsync();
            }

            recognizer = new SpeechRecognizer();

            //if (recognizer != null)
            //{
            //}
            //else
            //{
            //    //recognizer.Constraints?.Clear();
            //    //await recognizer.CompileConstraintsAsync();
            //}

            if (grammarFileConstraint != null)
            {
                recognizer.Constraints.Add(grammarFileConstraint);
            }

            SpeechRecognitionResult recognize = null;

            try
            {
                isRecognizing = false;
                SpeechStatusChanged?.Invoke(this, new SpeechArgs { Status = SpeechStatus.None });

                await recognizer.CompileConstraintsAsync();

                isRecognizing = true;
                SpeechStatusChanged?.Invoke(this, new SpeechArgs { Status = SpeechStatus.Listening });

                recognize = await (ui ? recognizer.RecognizeWithUIAsync() : recognizer.RecognizeAsync());
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.GetType() + ":" + e.Message);

                if (recognize != null)
                {
                    result.status = recognize.Status;
                }

                result.confidence = 5;
                return result;
            }
            finally
            {
                isRecognizing = false;
                SpeechStatusChanged?.Invoke(this, new SpeechArgs { Status = isUserStopped ? SpeechStatus.Stopped : SpeechStatus.None });
            }

            result.status = isUserStopped ? SpeechRecognitionResultStatus.UserCanceled : recognize.Status;

            if (constraints == null)
            {
                result.text = recognize.Text;
                return result;
            }

            result.confidence = (int) recognize.Confidence;

            var text = recognize.Text.ToUpperInvariant();

            var items2 = constraints.Split(';');
开发者ID:iot-alex,项目名称:virtual-shields-universal,代码行数:67,代码来源:Speech.cs

示例4: Talk

        private async void Talk()
        {
#if WINDOWS_PHONE_APP
            // Create an instance of SpeechRecognizer
            var speechRecognizer = new SpeechRecognizer();

            // Compile the dictation grammar by default
            await speechRecognizer.CompileConstraintsAsync();

            // Start recognition
            var speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync();

            // Add text to message that will be sent
            TextMessage += speechRecognitionResult.Text;
#endif
        }
开发者ID:nmetulev,项目名称:Modern-Gitter,代码行数:16,代码来源:RoomViewModel.cs

示例5: StartVoiceRecognition

		private async void StartVoiceRecognition()
		{
			await SpeakText( "Say Captains Log at any time to create a log entry." );

			speechRecognizerCaptainsLogCommand = new SpeechRecognizer();

			while ( !cancellationSource.IsCancellationRequested )
			{
				// Listen for user to say "Captains Log"
				ISpeechRecognitionConstraint commandConstraint = 
					new SpeechRecognitionListConstraint( new[] { "Captains Log", "Computer Captains Log" } );
				speechRecognizerCaptainsLogCommand.Constraints.Add( commandConstraint );
				await speechRecognizerCaptainsLogCommand.CompileConstraintsAsync();

				SpeechRecognitionResult commandResult = await speechRecognizerCaptainsLogCommand.RecognizeAsync();

				if ( commandResult.Status != SpeechRecognitionResultStatus.Success
					|| commandResult.Confidence == SpeechRecognitionConfidence.Rejected
					|| cancellationSource.IsCancellationRequested )
				{
					continue;
				}
				// Recognized user saying "Captains Log"

				// Listen for the user's dictation entry
				var captainsLogDictationRecognizer = new SpeechRecognizer();

				ISpeechRecognitionConstraint dictationConstraint = 
					new SpeechRecognitionTopicConstraint( 
						SpeechRecognitionScenario.Dictation, "LogEntry", "LogEntryDictation" );

				captainsLogDictationRecognizer.Constraints.Add( dictationConstraint );

				await captainsLogDictationRecognizer.CompileConstraintsAsync();

				captainsLogDictationRecognizer.UIOptions.ExampleText = "Boldly going where no man or woman has gone before.";
				captainsLogDictationRecognizer.UIOptions.AudiblePrompt = "Go ahead";
				captainsLogDictationRecognizer.UIOptions.IsReadBackEnabled = true;
				captainsLogDictationRecognizer.UIOptions.ShowConfirmation = true;

				SpeechRecognitionResult dictationResult = await captainsLogDictationRecognizer.RecognizeWithUIAsync();

				if ( dictationResult.Status != SpeechRecognitionResultStatus.Success
					|| dictationResult.Confidence == SpeechRecognitionConfidence.Rejected
					|| string.IsNullOrWhiteSpace( dictationResult.Text )
					|| cancellationSource.IsCancellationRequested )
				{
					captainsLogDictationRecognizer.Dispose();

					continue;
				}
				// Recognized user's dictation entry

				AddLogEntry( dictationResult.Text );

				captainsLogDictationRecognizer.Dispose();
			}

			speechRecognizerCaptainsLogCommand.Dispose();
		}
开发者ID:dannydwarren,项目名称:Cortana-Location-UWP,代码行数:60,代码来源:RecordNotesPage.xaml.cs

示例6: StartWithUi

        private async void StartWithUi()
        {
            _startListening.Visibility = Visibility.Collapsed;
            _startListeningWithUi.Visibility = Visibility.Collapsed;
            _stopListening.Visibility = Visibility.Visible;

            var selectedLanguage = (Windows.Globalization.Language)_topicLanguages.SelectedItem;

            recognizer = new SpeechRecognizer(selectedLanguage);

            recognizer.HypothesisGenerated += Recognizer_HypothesisGenerated;
            recognizer.RecognitionQualityDegrading += Recognizer_RecognitionQualityDegrading;
            recognizer.StateChanged += Recognizer_StateChanged;

            await recognizer.CompileConstraintsAsync();

            await recognizer.RecognizeWithUIAsync();
        }
开发者ID:MicrosoftDXGermany,项目名称:more-personal-computing,代码行数:18,代码来源:SpeechRecognitionPage.xaml.cs


注:本文中的SpeechRecognizer.RecognizeWithUIAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。