Confirmation with GetAndConfirmActivity
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
The GetAndConfirmActivity class is ideally suited for recognition and confirmation of a user's response that contains a single semantic item. This activity consists of two phases: the first phase attempts to recognize the user's response and the second phase provides a mechanism for the user to confirm or deny the recognized response. If the user confirms the recognized response, GetAndConfirmActivity stops. If the user does not confirm the response, the activity restarts in the recognition phase.
The example presented in this section is an implementation of explicit confirmation. For more information about this and other confirmation strategies, see Speech Application Dialog Concepts.
GetAndConfirmActivity Events
The two events on GetAndConfirmActivity that are used most often are TurnStarting and ConfirmationTurnStarting. TurnStarting is raised when a turn starts for the recognition phase of this activity. Similarly, ConfirmationTurnStarting is raised when a turn starts for this activity's confirmation phase.
To generate handlers for these events, right-click a GetAndConfirmActivity instance in the Speech Control Editor and then click Generate Handlers. Assuming that the name of the GetAndConfirmActivity instance is getSize, the names of the handlers are getSize_TurnStarting and getSize_ConfirmationTurnStarting.
Prompting the User for a Response
Prompt the user for the sort of response your application expects in the TurnStarting event handler. The following example shows a simple main prompt asking the user for a size: small, medium, or large.
private void getSize_TurnStarting(object sender, TurnStartingEventArgs e)
{
this.getSize.MainPrompt.SetText("Do you want small, medium, or large?");
}
Playing the User's Response and Asking for Confirmation
You can play the user's response and ask for confirmation of the response in the handler for the ConfirmationTurnStarting event. In the following example, the confirmation main prompt is used to ask whether the result recognized by the application is the same as what the user uttered.
private void getSize_ConfirmationTurnStarting(object sender, TurnStartingEventArgs e)
{
this.getSize.ConfirmationMainPrompt.SetText(string.Format("Did you say {0}?", this.getSize.RecognitionResult.Semantics.Value));
}