RecognizedPhrase Class
Assembly: System.Speech (in system.speech.dll)
Instances of RecognizedPhrase allow applications to obtain:
-
The text determined by a recognition engine as matching audio input, as a string, or a collection of the RecognizedWordUnit objects (see Text, and Words).
-
Homophone and specialized word substitution information (see Homophones, Grammar, and ReplacementWordUnits)
-
Information about recognition engine confidence in the match which returned for a particular RecognizedPhrase instance, and the Grammar and semantics used to obtain the match (see Confidence, Grammar,
The RecognitionResult object -- which returns recognition engine matches for audio input as detailed information about the best candidate phrases matching phrase, and a list of all candidate matching phrases -- inherits from RecognizedPhrase. Access to the RecognizedPhrase based information about the best matching candidate phrase returned by a recognition engine operations is typically obtained by using the RecognitionResult members inherited from RecognizedPhrase.
The example below show a display function which provides information about a recognized phrase from an instance of RecognizedPhrase to a user interface, (as well as some information about the recognizer state).
In fact care is taken to check if the result argument provided is in fact a RecognitionResult object, which inherits from RecognizedPhrase; if that is the case the addition information on the RecognitionResult object is displayed.
internal static void DisplayBasicPhraseInfo(Label label, RecognizedPhrase result, SpeechRecognizer recognizer) {
if (result != null && label != null) {// Blank
if (recognizer != null) { //Clear
label.Text += String.Format(
" Recognizer currently at: {0} mSec\n" +
" Audio Device currently at: {1} mSec\n",
recognizer.RecognizerAudioPosition.TotalMilliseconds,
recognizer.AudioPosition.TotalMilliseconds);
}
if (result != null) { //Clear
RecognitionResult recResult = result as RecognitionResult;
if (recResult != null) {
RecognizedAudio resultRecognizedAudio = recResult.Audio;
if (resultRecognizedAudio == null) {
label.Text += String.Format(
" Emulated input\n");
} else {
label.Text += String.Format(
" Candidate Phrase at: {0} mSec\n" +
" Phrase Length: {1} mSec\n" +
" Input State Time: {2}\n" +
" Input Format: {3}\n",
resultRecognizedAudio.AudioPosition.TotalMilliseconds,
resultRecognizedAudio.Duration.TotalMilliseconds,
resultRecognizedAudio.StartTime.ToShortTimeString(),
resultRecognizedAudio.Format.EncodingFormat.ToString());
}
}
label.Text += String.Format(" Confidence Level: {0}\n", result.Confidence);
if (result.Grammar != null) {
label.Text += String.Format(
" Recognizing Grammar: {0}\n" +
" Recognizing Rule: {1}\n",
((result.Grammar.Name != null) ? (result.Grammar.Name) : "None"),
((result.Grammar.RuleName != null) ? (result.Grammar.RuleName) : "None"));
}
if (result.ReplacementWordUnits.Count != 0) {
label.Text += String.Format(" Replacement text:\n");
foreach (ReplacementText rep in result.ReplacementWordUnits) {
label.Text += String.Format(" At index {0} for {1} words. Text: {2}\n",
rep.FirstWordIndex, rep.CountOfWords, rep.Text);
}
label.Text+=String.Format("\n\n");
}
}
}
}
System.Speech.Recognition.RecognizedPhrase
System.Speech.Recognition.RecognitionResult
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.