in FamilyNotes/Speech/SpeechManager.cs [576:655]
private void ContinuousRecognitionSession_ResultGenerated(
SpeechContinuousRecognitionSession sender,
SpeechContinuousRecognitionResultGeneratedEventArgs args)
{
if (args.Result.Status != SpeechRecognitionResultStatus.Success)
{
#if VERBOSE_DEBUG
Debug.WriteLine( "SpeechManager: ResultGenerated: {0}", args.Result.Status );
#endif
return;
}
// Unpack event arg data.
bool hasConstraint = args.Result.Constraint != null;
var confidence = args.Result.Confidence;
string phrase = args.Result.Text;
// The garbage rule doesn't have a tag associated with it, and
// the other rules return a string matching the tag provided
// when the grammar was compiled.
string tag = hasConstraint ? args.Result.Constraint.Tag : "unknown";
if (tag == "unknown")
{
#if VERBOSE_DEBUG
Debug.WriteLine( "SpeechManager: ResultGenerated: garbage rule hit" );
#endif
return;
}
else
{
#if VERBOSE_DEBUG
string msg = String.Format( "SpeechManager: ResultGenerated: {0}", phrase );
Debug.WriteLine( msg );
#endif
}
if (hasConstraint && args.Result.Constraint.Type == SpeechRecognitionConstraintType.List)
{
// The List constraint type represents speech from
// a compiled grammar of commands.
CommandVerb verb = GetPhraseIntent(phrase);
// You may decide to use per-phrase confidence levels in order to
// tune the behavior of your grammar based on testing.
if (confidence == SpeechRecognitionConfidence.Medium ||
confidence == SpeechRecognitionConfidence.High)
{
Person person = null;
if (PhraseToPersonDictionary.ContainsKey(phrase))
{
person = PhraseToPersonDictionary[phrase];
}
// Raise the PhraseRecognized event. Clients with thread affinity,
// like in a XAML-based UI, need to marshal the call to the
// client's thread.
PhraseRecognizedEventArgs eventArgs = new PhraseRecognizedEventArgs(
person,
phrase,
verb,
args);
OnPhraseRecognized(eventArgs);
}
}
else if (hasConstraint && args.Result.Constraint.Type == SpeechRecognitionConstraintType.Topic)
{
// The Topic constraint type represents speech from dictation.
// Raise the PhraseRecognized event. Clients with thread affinity,
// like in a XAML-based UI, need to marshal the call to the
// client's thread.
PhraseRecognizedEventArgs eventArgs = new PhraseRecognizedEventArgs(
null,
phrase,
CommandVerb.Dictation,
args);
OnPhraseRecognized(eventArgs);
}
}