Walkthrough: Add a Command
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.
Use command activities in Speech Server to handle user commands that are not part of the current question and answer dialog. Voice response applications provide three command activities, summarized in the following table.
Activity | Description |
---|---|
Represents a digression in the dialog flow caused by a request from the user. |
|
Defines a specialized type of CommandActivity that is used to initiate a more explanatory prompt for the next turn. |
|
Activates the playing of the repeat prompt during the next turn. |
This walkthrough demonstrates how to add a HelpCommand activity to a voice response application. The following steps can also be used to add Command and RepeatCommand activities to a voice response application.
Prerequisites
To complete this walkthrough, you need:
- Speech Server.
- Sufficient permissions to create and debug ASP.NET Web application projects on the computer where Speech Server is installed.
Open a New Project
To create a voice response application
Create a new voice response application named CommandApplication.
For more information, see How to: Create a Voice Response Application.
Rather than creating new grammar files for the QuestionAnswer activity and the HelpCommand activity, import two existing grammars from a sample application. In Windows Explorer, copy the grammar files Drinks.gbuilder and Help.gbuilder from the HandleErrors sample to the Grammars folder in the current application, CommandApplication.
For information about the location of this sample application, see HandleErrors (Managed Code Sample).
In Solution Explorer, right-click the Grammars folder, click Add, and then click Existing Item.
In the Add Existing Item dialog box, expand Grammars, select the two grammar files Help.gbuilder and Drinks.gbuilder, and then click Add.
In Solution Explorer, double-click Drinks.gbuilder.
On the Grammar menu, click Compile All. Repeat this step and the previous step for Help.gbuilder.
Create the Dialog Workflow
Add a QuestionAnswer activity to Workflow Designer.
To add a QuestionAnswer activity
On the View menu, click Toolbox.
In the Toolbox, click Speech Dialog Components to display speech activities.
Drag and drop a QuestionAnswer speech dialog component onto the design surface between answerCallActivity1 and disconnectCallActivity1.
Right-click QuestionAnswer1, click Properties, and then set the Name property for QuestionAnswer1 to askDrinkType.
Add a prompt to the QuestionAnswer activity.
To add a prompt
In Solution Explorer, right-click VoiceResponseWorkflow1.cs and click View Designer.
In Workflow Designer, right-click askDrinkType, and then select Property Builder.
In the QuestionAnswer Property Builder dialog box, click the Prompts tab, type Would you like a mocha, latte, or cappuccino? in the Main box, and then click OK.
Connect the Drinks.gbuilder grammar to the QuestionAnswer activity.
To specify the QuestionAnswer grammar
In Workflow Designer, right-click askDrinkType, and then click Property Builder.
In the QuestionAnswer Property Builder dialog box, click the Grammar tab, select the DrinkTypeResponse node, and then click OK.
Add Command
Add a HelpCommand activity to the Command Handler.
To add an activity to the Command Handler
In the lower left corner of Workflow Designer, click View Commands.
In the Toolbox, drag and drop a HelpCommand speech dialog component onto Drop a Command here.
Right-click the HelpCommand, click Properties, and then in the Properties window set the Grammar property to point to Help_en-US.cfg.
In the Toolbox, drag and drop a Statement speech dialog component onto Drop Activities Here.
Set the Name property to saidHelp, and then add a main prompt of "You asked for Help."
In the Toolbox, drag and drop a GoTo speech dialog component onto Drop a Command here following the saidHelp activity.
Set the Name property to goToDisconnect.
Right-click goToDisconnect, and then click Property Builder.
In the GoTo Property Builder dialog box, select disconnectCallActivity1, and then click OK. This causes the application to disconnect the call after speaking the prompt.
Run the Application
To build and run the application
Press F5 to open the debugger.
In the Debugging Not Enabled dialog box, click OK.
In the Voice Response Debugging Window dialog box, click Call when the application is completely initialized.
To answer the question, click the User Input tab, select Text Input, type help, and then click Submit.
The application responds with "You asked for help" and then disconnects.
See Also
Other Resources
Create Managed Code Voice Response Applications
Managed Code Sample Applications