Share via


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

CommandActivity

Represents a digression in the dialog flow caused by a request from the user.

HelpCommandActivity

Defines a specialized type of CommandActivity that is used to initiate a more explanatory prompt for the next turn.

RepeatCommandActivity

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

  1. Create a new voice response application named CommandApplication.

    For more information, see How to: Create a Voice Response Application.

  2. 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).

  3. In Solution Explorer, right-click the Grammars folder, click Add, and then click Existing Item.

  4. In the Add Existing Item dialog box, expand Grammars, select the two grammar files Help.gbuilder and Drinks.gbuilder, and then click Add.

  5. In Solution Explorer, double-click Drinks.gbuilder.

  6. 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

  1. On the View menu, click Toolbox.

  2. In the Toolbox, click Speech Dialog Components to display speech activities.

  3. Drag and drop a QuestionAnswer speech dialog component onto the design surface between answerCallActivity1 and disconnectCallActivity1.

  4. 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

  1. In Solution Explorer, right-click VoiceResponseWorkflow1.cs and click View Designer.

  2. In Workflow Designer, right-click askDrinkType, and then select Property Builder.

  3. 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

  1. In Workflow Designer, right-click askDrinkType, and then click Property Builder.

  2. 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

  1. In the lower left corner of Workflow Designer, click View Commands.

  2. In the Toolbox, drag and drop a HelpCommand speech dialog component onto Drop a Command here.

  3. Right-click the HelpCommand, click Properties, and then in the Properties window set the Grammar property to point to Help_en-US.cfg.

  4. In the Toolbox, drag and drop a Statement speech dialog component onto Drop Activities Here.

  5. Set the Name property to saidHelp, and then add a main prompt of "You asked for Help."

  6. In the Toolbox, drag and drop a GoTo speech dialog component onto Drop a Command here following the saidHelp activity.

  7. Set the Name property to goToDisconnect.

  8. Right-click goToDisconnect, and then click Property Builder.

  9. 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

  1. Press F5 to open the debugger.

  2. In the Debugging Not Enabled dialog box, click OK.

  3. In the Voice Response Debugging Window dialog box, click Call when the application is completely initialized.

  4. 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