本文整理汇总了C#中SpeechRecognizer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechRecognizer.Dispose方法的具体用法?C# SpeechRecognizer.Dispose怎么用?C# SpeechRecognizer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpeechRecognizer
的用法示例。
在下文中一共展示了SpeechRecognizer.Dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitRecognizer
public async static Task<SpeechRecognizer> InitRecognizer()
{
try
{
if (null != recognizer)
{
recognizer.Dispose();
recognizer = null;
}
recognizer = new SpeechRecognizer(SpeechRecognizer.SystemSpeechLanguage);
recognizer.Constraints.Add(
new SpeechRecognitionListConstraint(
new List<string>()
{
speechResourceMap.GetValue("account page", speechContext).ValueAsString,
speechResourceMap.GetValue("audit page", speechContext).ValueAsString,
speechResourceMap.GetValue("finace page", speechContext).ValueAsString,
speechResourceMap.GetValue("transfer page", speechContext).ValueAsString
}, "goto"));
SpeechRecognitionCompilationResult compilationResult = await recognizer.CompileConstraintsAsync();
if (compilationResult.Status != SpeechRecognitionResultStatus.Success)
{
recognizer.Dispose();
recognizer = null;
}
//string uiOptionsText = string.Format("Try saying '{0}', '{1}' or '{2}'",
// speechResourceMap.GetValue("account page", speechContext).ValueAsString,
// speechResourceMap.GetValue("audit page", speechContext).ValueAsString,
// speechResourceMap.GetValue("audit page", speechContext).ValueAsString);
//recognizer.UIOptions.ExampleText = uiOptionsText;
return recognizer;
}
catch(Exception e)
{
return null;
}
}
示例2: InitializeAsync
public override async Task InitializeAsync()
{
if (speechRecognizer == null)
{
try
{
var recognizer = new SpeechRecognizer(ConvertAILangToSystem(config.Language));
recognizer.StateChanged += Recognizer_StateChanged;
// INFO: Dictation is default Constraint
//var webSearchGrammar = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "dictation");
//recognizer.Constraints.Add(webSearchGrammar);
await recognizer.CompileConstraintsAsync();
lock (speechRecognizerLock)
{
if (speechRecognizer == null)
{
speechRecognizer = recognizer;
}
else
{
recognizer.Dispose();
}
}
}
catch (Exception e)
{
if ((uint)e.HResult == HRESULT_LANG_NOT_SUPPORTED)
{
throw new AIServiceException(string.Format("Specified language {0} not supported or not installed on device", config.Language.code), e);
}
throw;
}
}
}
示例3: InitializeSpeechRecognizer
private async void InitializeSpeechRecognizer()
{
if (speechRecognizer != null)
{
this.speechRecognizer.Dispose();
this.speechRecognizer = null;
}
speechRecognizer = new SpeechRecognizer();
var topicConstraing = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development");
speechRecognizer.Constraints.Add(topicConstraing);
await speechRecognizer.CompileConstraintsAsync();
var operation = await speechRecognizer.RecognizeAsync();
if (!this.Completed && operation.Status == SpeechRecognitionResultStatus.Success)
{
this.Completed = true;
ResultGenerated(operation.Text);
speechRecognizer.RecognizeAsync().Cancel();
speechRecognizer.Dispose();
speechRecognizer = null;
}
}
示例4: 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();
}
示例5: InitializeSpeechRecognizer
private async void InitializeSpeechRecognizer()
{
try
{
if (speechRecognizer != null)
{
speechRecognizer.RecognizeAsync().Cancel();
speechRecognizer.RecognizeAsync().Close();
this.speechRecognizer.Dispose();
this.speechRecognizer = null;
}
speechRecognizer = new SpeechRecognizer();
var topicConstraing = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development");
speechRecognizer.Constraints.Add(topicConstraing);
await speechRecognizer.CompileConstraintsAsync();
this.Operation = await speechRecognizer.RecognizeAsync();
if (Operation.Status == SpeechRecognitionResultStatus.Success)
{
ResultGenerated(Operation.Text);
speechRecognizer.RecognizeAsync().Cancel();
speechRecognizer.Dispose();
speechRecognizer = null;
}
}
catch (Exception)
{
}
}