Share via


Walkthrough: Add a Speech Event

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 speech event activities in Speech Server voice response applications to escalate silence and no recognition prompts. When a caller remains silent or makes an utterance that is not recognized, a speech application should play appropriate escalating silence or no recognition prompts, such as "If you are not sure what to say, you can always say help," or "you can press one for a mocha, two for a latte, or three for a cappuccino."

For more information about speech event activities, see the sample application HandleErrors (Managed Code Sample).

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 the Dialog Workflow

Add QuestionAnswer and Statement activities to Workflow Designer.

To add QuestionAnswer and Statement activities

  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 under Activities.

  5. In Windows Explorer, copy the grammar file Drinks.gbuilder from the HandleErrors sample to the Grammars folder in the current application, SpeechEventApplication.

    For information about the location of this sample application, see HandleErrors (Managed Code Sample).

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

  7. In the Add Existing Item dialog box, expand Grammars, select Drinks.gbuilder, and then click Add.

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

  9. On the Grammar menu, click Compile All.

  10. In Solution Explorer, right-click VoiceResponseWorkflow1.cs, click View Designer, and then drag and drop a Statement speech dialog component onto the design surface between askDrinkType and disconnectCallActivity1.

  11. Right-click Statement1, click Properties, and then set the Name property for the statement to finish.

Add prompts to the QuestionAnswer and Statement activities.

To add prompts

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

  2. In the Statement Property Builder dialog box, type Goodbye in the Main box, and then click OK.

  3. Right-click askDrinkType, and then click Property Builder.

  4. In the QuestionAnswer Property Builder dialog box, click the Prompts tab, and then add the prompts listed in the following table.

Prompt Type Prompt Text

Main

Would you like a mocha, latte, or cappuccino?

Silence

Mocha, latte, or cappuccino?

Escalated Silence

If you are not sure what to say, you can always say help. Or you can press 1 for a mocha, 2 for a latte, or 3 for a cappuccino.

No Recognition

What was that?

Escalated No Recognition

I did not get that either. Please say mocha, latte, or cappuccino.

Connect the grammar to the QuestionAnswer activity.

To specify a 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.

    This specifies a speech grammar.

  3. Repeat the operation on the DTMF Grammar node.

    This selection specifies a DTMF grammar.

  4. Build the solution.

Add Speech Events and Code

Add activities to the SpeechEvents Handler.

To add speech event activities and code

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

  2. In the Toolbox, drag and drop a ConsecutiveNoRecognitionsSpeechEvent speech dialog component onto Drop a SpeechEvent Here.

  3. In the Properties window, set MaximumNorecognitions to 4.

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

  5. Set the Name property to noInputError, and then type Thanks for calling Fourth Coffee as the main prompt.

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

  7. Set the Name property to goToFinishActivity.

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

  9. In the GoTo Property Builder dialog box, select finish, and then click OK.

Add code to implement three strikes behavior.

To add code to implement three strikes behavior

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

  2. Right-click askDrinkType, and then click Generate Handlers.

  3. Add the following statements to the TurnStarting event handler.

    // set the appropriate error message based on the number of tries in the QuestionAnswer
    switch (count)
    {
      case 3:
    
        // we use the EscalatedNoRecognitionPrompt
        // because when we enter the third time the AskDrinkType question the
        // NoRecognition and EscalatedNoRecognitionPrompt already completed and the last one
        // to be handled was EscalatedNoRecognitionPrompt prompts
        this.askDrinkType.Prompts.EscalatedNoRecognitionPrompt.SetText("If you want a mocha, press1. For a latte, press 2.");
        break;
      }
      count++;
    
  4. Add the following statement at the top of the class, between the class declaration and the Workflow1 class constructor.

    private int count;
    
  5. Build the project, and then resolve any errors.

Run the Application

To build and run the application

  1. Press F5 to open the debugger.

  2. In the Voice Response Debugging Window dialog box, click Call.

  3. To answer the question, select Text Input on the User Input tab, enter text, and then click Submit.

    The application responds with a "What was that?" no recognition prompt.

  4. Select Text Input, and then click Submit a second time.

    The application responds with "I did not get that either. Please say mocha, latte, or cappuccino." This is the escalated no recognition prompt.

  5. Select Text Input, and then click Submit a third time.

    The application responds with "If you want a mocha, press 1. For a latte, press 2." This is the prompt specified in code when the counter reaches 3.

  6. Select Text Input, and then click Submit a fourth time.

    At this point, the value set for the MaximumNoRecognition property is met and the ConsecutiveNoRecognitionsSpeechEventActivity activity runs, which in turn triggers the Statement and GoTo activities in the SpeechEvents Handler.

See Also

Other Resources

Create Managed Code Voice Response Applications
Managed Code Sample Applications