ReplacementText Class
Contains originally recognized text replace using speech normalization by a recognition engine.
Assembly: System.Speech (in System.Speech.dll)
Speech normalization is the use of special constructs or symbols to express speech in writing. For example, normalization can replace the spoken words "a dollar and sixteen cents" with "$1.16" in output text.
For example, if an audio input was:
july four at twelve thirty one PM, I bought a one point six kilograms of fish for fourteen dollars and six cents, at the pike market in seattle washington nine eight one two two
The normalized output might be:
July 4 at 12:31 PM, I bough a 1.6 kg of fish for $14.06, at the pike market in Seattle WA 98122
In this case there are five substitutions, each described by an instance of ReplacementText.
Using the ReplacementText object, an application can determine:
-
The location and number of words replaced by normalization (form more information, see FirstWordIndex or CountOfWords).
-
The replaced text and its display attributes (for more information, see Text, and DisplayAttributes).
Instances of ReplacementText are typically obtained as members of the [System.Collections.ObjectModel.Collection] object returned by the ReplacementWordUnits property on RecognizedPhrase (or classes which inherit from RecognizedPhrase such as RecognitionResult) when returned text has been normalized.
In the example below, information about a RecognizedPhrase object returned by a recognition engine is displayed to a user interface.
The code where information about each originally recognized phrase replaced by normalization is displayed using ReplacementText instances obtained ReplacementWordUnits is highlighted.
internal static void DisplayBasicPhraseInfo(Label label, RecognizedPhrase result, SpeechRecognizer rec) {
if (result != null && label != null) {// Blank
if (rec != null) { //Clear
label.Text += String.Format(
" Recognizer currently at: {0} mSec\n" +
" Audio Device currently at: {1} mSec\n",
rec.RecognizerAudioPosition.TotalMilliseconds,
rec.AudioPosition.TotalMilliseconds);
}
if (result != null) { //Clear
RecognitionResult recResult = result as RecognitionResult;
if (recResult != null) {
RecognizedAudio resultAudio = recResult.Audio;
if (resultAudio == 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",
resultAudio.AudioPosition.TotalMilliseconds,
resultAudio.Duration.TotalMilliseconds,
resultAudio.StartTime.ToShortTimeString(),
resultAudio.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("Replacementtext:\n");foreach(ReplacementTextrepinresult.ReplacementWordUnits){stringrepText=rep.Text;//Addtrailingspacesif((rep.DisplayAttributes&DisplayAttributes.OneTrailingSpace)!=0){repText+="";}if((rep.DisplayAttributes&DisplayAttributes.TwoTrailingSpaces)!=0){repText+="";}if((rep.DisplayAttributes&DisplayAttributes.ConsumeLeadingSpaces)!=0){
repText=repText.TrimStart(); } if ((rep.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0) { repText = repText.TrimEnd(); }label.Text+=String.Format("Atindex{0}for{1}words.Text:\"{2}\"\n",rep.FirstWordIndex,rep.CountOfWords,repText);}label.Text+=String.Format("\n\n");}
}
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.