RecognizedPhrase Class
Represents detailed information about a candidate phrase found by a recognition engine as matching audio input.
Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
<SerializableAttribute> _
<DebuggerDisplayAttribute("{Text}")> _
Public Class RecognizedPhrase
[SerializableAttribute]
[DebuggerDisplayAttribute("{Text}")]
public class RecognizedPhrase
[SerializableAttribute]
[DebuggerDisplayAttribute(L"{Text}")]
public ref class RecognizedPhrase
/** @attribute SerializableAttribute() */
/** @attribute DebuggerDisplayAttribute("{Text}") */
public class RecognizedPhrase
SerializableAttribute
DebuggerDisplayAttribute("{Text}")
public class RecognizedPhrase
Remarks
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.
Inheritance Hierarchy
System.Object
Microsoft.Speech.Recognition.RecognizedPhrase
Microsoft.Speech.Recognition.RecognitionResult
Example
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");
}
}
}
}
Thread Safety
All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.
Platforms
Development Platforms
Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition
Target Platforms
See Also
Reference
RecognizedPhrase Members
Microsoft.Speech.Recognition Namespace
RecognitionResult Class
RecognizedWordUnit