本文整理汇总了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;
}
示例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();
}
示例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(';');
示例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
}
示例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();
}
示例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();
}