Confirming Responses
This topic is the sixth of seven tutorial topics covering tools in the Microsoft Speech Application SDK Version 1.1 (SASDK). This section of the tutorial uses Speech Control Editor, which is the all-purpose tool for assembling a working speech-enabled Web application in Microsoft Visual Studio .NET 2003. Speech Control Editor manipulates ASP.NET Speech Controls that produce Speech Application Language Tags (SALT) and JScript on the client. The developer uses Speech Control Editor to specify prompts to speak to the user, to recognize answers using grammars, and to confirm the answers.
For reference information on Speech Control Editor, see Creating Speech-Enabled Web Pages for an introduction to the topic, and Recognizing and Confirming Answers for specifics on QA controls. In addition, Designing Dialogue Flow contains guidelines for designing voice-only applications.
This sequence of tutorials demonstrates how to build a simple voice-only ASP.NET Web application using the SASDK. Specifically, the tutorials demonstrate building a Start page of an imaginary pizza ordering service, for use by telephony Speech Application Language Tags (SALT) clients.
The procedures for creating the pizza ordering service application build on each other. Performing the procedures in sequence is therefore important.
Confirming the Responses
The application needs to confirm the responses that it has recognized to ensure that it has not recognized some phrase incorrectly, and to give the caller a chance to correct the error if it exists. In this application, if the caller indicates that the information is not correct, the dialogue flow returns to the first prompt for a response from the user, SizeQA, and repeats all the prompts again. The sample and reference applications included in the SASDK demonstrate other confirmation strategies, as well as other dialogue designs.
To add the confirmation QA control
- From the Speech tab on the Toolbox, drag a QA control onto PizzaPanel.
- Right-click the QA control, and select Property Builder.
- In the ID edit box, change the name of the control to ConfirmQA.
- Select Voice Output.
- Select the PlayOnce item.
This specifies that the application will play this prompt only once while the tutorial application is first being tested.
To add semantic values to ConfirmQA
- In the tree view pane on the left, select Input.
- In the right pane, click Add Existing Grammar.
- In Add Existing Grammar, click Browse next to the Grammar Path edit box.
- In Grammar URL browser, click Grammars in the Projects: pane, and then double-click PizzaOrder.grxml in the Contents of 'Grammars' pane.
- In Add Existing Grammar, click Browse in the Active Rule section.
- In Rule Browser, select Confirm from the list of rules, and click Select Active Rule.
- In Add Existing Grammar, click OK.
- In ConfirmQA Properties, click XPathTrigger Sample Sentence Tool.
- In the Sample speech input edit box, type Yes, and click Go.
- On the Answers tab, double-click the first SemanticItem drop-down list box, and select siYes.
- Click the corresponding XPathTrigger drop-down list box, and select SML/Yes.
That binds the semantic information in SML/Yes to the siYes SemanticItem in SemanticMap. - In the Sample speech input edit box, now type No, and click Go.
- On the Answers tab, double-click the next SemanticItem drop-down list box, and select siNo.
- Click the corresponding XPathTrigger drop-down list box, and select SML/No.
That binds the semantic information in SML/No to the siNo SemanticItem in SemanticMap. - Click OK.
- Right-click the Default.aspx tab, and from the context menu, select Save Default.aspx.
Playing back the caller's responses as a prompt
To play back the caller's responses as a prompt, it is necessary to create a prompt function. This prompt function extracts the text from the semantic items that were filled when the caller responded to previous prompts. It takes the size and phone number text from the siSize, and the siPhoneNumberText, concatenates them with some phrases in the prompt database to produce a prompt that is not in the prompt database. This also requires a small function to extract the contents of the semantic items from the SemanticMap control. For more information on prompt functions, see Using Prompt Databases.
To create the prompt function file
- Right-click the ConfirmQA control, and select Property Builder.
- In the tree view pane on the left, click Voice Output.
- In the Prompt options section, clear the BargeIn check box.
In this case, the caller needs to listen to the entire prompt in order to be able to decide if the order details and the telephone number are correct. - Click the Prompt Function radio button.
- Click the link Manage this page's prompt function script files.
- On the Manage 'Default.aspx' Prompt Function Script Files dialog box, select New.
- On the New Prompt Function Script File dialog box, enter PizzaOrder into the File name edit box.
- Click Save, and then click OK.
- From the drop-down list under the Prompt Function radio button, select <New...>.
The New Prompt Function dialog box appears, with PizzaOrder.pf indicated as the prompt function file and ConfirmQA_prompt as the prompt function. - Click OK.
To add parameters for the ConfirmQA_prompt function
On ConfirmQA Properties, click Edit prompt function file....
On the message box that comes up, click OK.
In the table of parameters, select the row under the History parameter and double-click the cell under Parameter Name.
Type the following parameter name: sPhoneNumberText.
Double-click the cell under Validation Value.
In the Validation Values dialog box, enter "four two five five five five zero nine zero zero" (with the quote marks).
In a pass through the solution to validate prompts, this value is used.Click OK.
Double-click the cell under Runtime Value, and enter the following function call: GetSIValue(siPhoneNumberText).
In a subsequent step, you'll write this function in the HTML on Default.aspx.Similarly, enter the following items in the table:
Parameter Name Validation Values Runtime Value sSize "large"
"medium"
"small"GetSIValue(siSize) When the table is complete, it looks like the following illustration.
Copy the following function body, paste it into a plain text editor, copy it from the plain text editor and paste it into the function ConfirmQA_prompt_inner edit box, overwriting the default function body:
{ var sConfirmPromptStart = "You ordered a "; var sConfirmPromptMid = " pizza, and your telephone number is "; var sConfirmPromptEnd = " Is that correct?"; var sPrompt = "";
sPrompt = sConfirmPromptStart + sSize + " " + sConfirmPromptMid; sPrompt = sPrompt + sPhoneNumberText + sConfirmPromptEnd; return(sPrompt); }
Note The spaces around the strings in the function body are important. If they are not present, the text in the strings is concatenated with the semantic items, and in most cases, the prompt database will not have recorded audio to match. In that case, the text-to-speech (TTS) engine plays the prompts.
- The entire Prompt Function pane now looks like the following illustration.
- Right-click the PizzaOrder.pf tab, and from the context menu, select Save PizzaOrder.pf.
To retrieve the semantic values
The prompt function needs to retrieve the semantic items from the SemanticMap, and set its parameters equal to those values. The following Jscript function in the HTML on Default.aspx retrieves the value of the SemanticItem that it gets as a parameter. This new function is called by the ConfirmQA_prompt function, which was added in the previous section of this topic. It is enclosed in CDATA tags so the SALT interpreter does not try to interpret it.
Click the Default.aspx tab.
At the bottom of the design canvas, click HTML.
The HTML view of Default.aspx opens in a source editor.Copy the following script element, paste it into a plain text editor, copy it from the plain text editor, and paste it into the source editor just above the opening <form> tag of the HTML.
<SCRIPT> // <![CDATA[ function GetSIValue(theSI) { return(theSI == null ? null : theSI.value); } // ]]> </SCRIPT>
The source editor now looks like the following illustration:
- Right-click the Default.aspx tab, and from the context menu, select Save Default.aspx.
To set the order of ConfirmQA
Dropping ConfirmQA onto the PizzaPanel put it last in the default execution order for added QA controls. ConfirmQA, however, should play before ThanksQA, so it needs to move up in the execution order.
- Click the Default.aspx tab.
- At the bottom of the design canvas, click Design.
The Design canvas of Default.aspx opens. - From the View menu, click Speech Controls Outline.
The Speech Controls Outline shows the execution order of the controls in an application, and if expanded, shows additional features of the controls. In this case, for instance, some controls have Answers. - In Speech Controls Outline, select ConfirmQA.
- At the top of the pane, click the up arrow once to move the control in the order between PhoneQA and ThanksQA.
The Speech Controls Outline should now look like the following illustration.
To check the prompt playback
- On the Debug menu select Start. SASDK first builds the application, and then opens Speech Debugging Console and Telephony Application Simulator (TASim), with TASim on top.
- On TASim, click Dial. Through your headset or speakers, the application plays back the prompts in all the QA controls, one after the other, from the prompt database. To respond to prompts, on Speech Debugging Console click Use Audio and speak after Status indicates Listening. This time, the application asks for confirmation of the information provided.
- Close Speech Debugging Console and TASim.
Note If the microphone is configured improperly, the results of this check may be unexpected, such as incomplete prompts, or missing information in the confirmation prompt. If this happens, it may be necessary to configure the microphone, as described in the section "Before Beginning the Tutorial," in Speech Application SDK Tutorial.
At this point, the prompt played back by the prompt function uses the voice produced by the TTS engine. The previous section recorded all the prompts, so something new has appeared in the prompts. The next section of the tutorial, Debugging Applications, demonstrates another method for debugging prompts, and determining what happened.
Handling Confirmations
If the response to the question, Is that correct? is Yes in response to the prompt from ConfirmQA, then the dialogue flow simply continues on to ThanksQA and the application terminates.
If the response, however, is No, the application needs to take different action. In this case, the dialogue flow begins again at the SizeQA prompt and continues through the prompts until the ConfirmQA prompt again. The onNotConfirmed function referred to in the OnClientChanged property of the siNo semantic item clears the values of the semantic items to which the QA controls refer. That starts the dialogue flow again from the first control in the speech index order with empty semantic items. In order to have the prompts play again if the caller does not confirm the information, it is first necessary to clear the PlayOnce item in properties of the QA controls.
For more information on the activation order of controls, see Activation and Semantic Processing.
To clear the PlayOnce properties
- Right-click SizeQA, and select Property Builder.
- In the tree view pane on the left, select Voice Output .
- Clear PlayOnce.
- Click OK.
- Repeat steps 1 through 4 for PhoneQA, and ConfirmQA.
To handle a negative confirmation
Right-click SemanticMap, select Property Builder.
In the tree view pane on the left, select siNo.
In the OnClientChanged edit box, type onNotConfirmed.
The script for this handler goes into the HTML markup on Default.aspx.Click OK.
At the bottom of the design canvas, click HTML.
The HTML view of Default.aspx opens in a source editor.Copy the following function body, paste it into a plain text editor, copy it from the plain text editor, and paste it into the source editor inside the SCRIPT tag element previously inserted, just above the closing tag of the CDATA element.
//Restarts the dialog if user doesn't confirm the information. function onNotConfirmed() { if(siNo.value == "No") { siSize.Clear(); siPhoneNumberText.Clear(); siPhoneNumberAreaCodeDigits.Clear(); siPhoneNumberLocalDigits.Clear(); siYes.Clear(); siNo.Clear(); siCancel.Clear(); } return; }
The function checks to ensure that the semantic value of siNo is "No," and if so, it clears the values of all the semantic items in the semantic map.
The source editor now looks like the following illustration:
- Right-click the Default.aspx tab, and from the context menu, select Save Default.aspx.
Terminating the Application Properly
The application uses an AnswerCall control to make the proper connections to the telephony source. When the application terminates, it needs a DisconnectCall control to break those connections properly.
To use the DisconnectCall control
- Select the Default.aspx tab.
- Select Design at the bottom of the pane.
- On the Toolbox, select Speech, and then drag a DisconnectCall control onto the design canvas.
- Right-click the Default.aspx tab, and from the context menu, select Save Default.aspx.
Canceling the Order
Applications can use Command controls to listen to all speech input for a given scope of the application, and take action if a response is a recognized phrase in the control's grammar. Cancellation, Help and Navigation commands are common uses for these controls. See the sample Using Global Commands and Context-sensitive Help for more information. The tutorial application uses a simple control to cancel the order entirely and terminate the application.
To set up the Command control for order cancellation
On the Toolbox, select Speech, and then drag a Command control onto the design canvas.
Right-click Command1, and select Property Builder.
Select Command in the treeview pane. In the Speech Settings Item drop-down list, select SpeechControlSettingsItem1.
In the Scope drop-down list, select PizzaPanel.
In the Type edit box, enter Cancel.
In the tree view pane on the left, select Input.
On the Grammar tab, set the grammar as an existing grammar, choosing PizzaOrder.grxml as the grammar file, and Cancel as the active rule.
Click the XPathTrigger Sample Sentence Tool button, enter Cancel into the Sample speech input edit box, and click Go.
The tool now shows the SML that the SR engine returned.In the Command trigger section, in the XPathTrigger drop-down list box, select SML/Cancel.
In the Client Side Event section, in the OnClientCommand edit box, enter CancelFunction. The body of this function is added later in the tutorial.
The script in this function sets the activation state of the QA controls to false, so they are not activated again.In the tree view pane on the left, select Voice Output.
Click the Inline Prompt radio button, and enter the following inline prompt in the edit box:
Your order has been canceled. Goodbye.
Click OK.
To set the state of the QA controls
By default, if no client activation is specified for a control, its activation state is true. That means that it is activated any time it comes up in the dialogue flow, and its semantic items are not complete. In order to use the Command control to cancel the pizza order and terminate the application, it is necessary to set the state of all the QA controls to false. This requires a ClientActivation function for each control. It is the same for all the controls in this application, and initially sets the activation state of the control to true. CancelFunction sets the variable that the ClientActivation function returns to false. Then when the control becomes active in the dialogue flow, the ClientActivation function returns false, and the control does not activate, even though its semantic items may not be complete.
- Right-click SizeQA, and select Property Builder.
- In the Activation section, in the ClientActivationFunction edit box, type ActivateQA.
Note The AllowCommands box is already checked by default. This allows Command controls to listen for responses and take action at the same time the QA control is active.
- Click OK.
- Repeat steps 1 through 3 for PhoneQA, ConfirmQA, and ThanksQA.
To insert the script
- At the bottom of the design canvas, click HTML.
The HTML view of Default.aspx opens in a source editor. - Copy the following function body, paste it into a plain text editor, copy it from the plain text editor, and paste it into the source editor inside the SCRIPT tag element previously inserted, just above the closing tag of the CDATA element.
// ActivateQA is the ClientActivationFunction for the QA controls // Until the CancelFunction sets the value of activeQA to false, // it is always true. var activeQA=true; function ActivateQA() { return activeQA; } function CancelFunction() { activeQA = false; }
The ActivateQA function returns the value of the variable activeQA. When the application starts, this variable is set to true. The CancelFunction sets that variable to false. After that, when the ActivateQA function is called, it returns true. - Right-click the Default.aspx tab, and from the context menu, select Save Default.aspx.
The design canvas should now look something like the following illustration.
Confirming the Dialogue Flow
The dialogue flow for the application is now complete. The application plays the prompts, waits for responses, replays the relevant responses, and confirms the responses. If the caller confirms the responses, the application plays a concluding prompt and terminates. If the caller does not confirm the responses, the application clears all the semantic items and restarts playing prompts with the SizeQA control. It is now possible to confirm the flow of the dialogue by running it in the debuggers, and answering Yes or No to the confirmation prompt.
Note Because the PlayOnce property of QA controls is now cleared in order to be able to reactivate the controls on non-confirmation, the controls also now replay if the silence time-out is exceeded or if the speech recognition engine does not recognize a response. A production application would have counters for each prompt and a way to determine the confidence of the recognition. It could give a different prompt after an unrecognized response or it could change the dialogue flow after a certain number of failed attempts to get a recognizable response. For more information, see the samples Employing Confirmation and Correction Strategies and Responding to Silence and Unrecognized Input.
To confirm the dialogue flow
- On the Debug menu select Start.
- On TASim, click Dial.
- Respond to the prompts as they play.
- When asked if the responses are correct, respond No.
The application should begin again with the prompt asking for the size. - Again, respond to the prompts as they play.
- When asked if the responses are correct, respond Yes.
The application should play its thanks prompt, and then terminate. - Close Speech Debugging Console and TASim.
To | See |
---|---|
Go to the next step | Debugging Applications |
Start from the beginning | Creating a Speech Project |
Get more information on prompts and prompt functions | Using Prompt Databases Playing a Prompt across Page Transitions Constructing Natural-sounding Recorded Prompts |
Get more information on commands | Using Global Commands and Context-sensitive Help |