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 a new voice response application named SpeechEventApplication.
For more information, see How to: Create a Voice Response Application.
Create the Dialog Workflow
Add QuestionAnswer and Statement activities to Workflow Designer.
To add QuestionAnswer and Statement activities
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 under Activities.
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).
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 Drinks.gbuilder, and then click Add.
In Solution Explorer, double-click Drinks.gbuilder.
On the Grammar menu, click Compile All.
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.
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
In Workflow Designer, right-click finish, and then click Property Builder.
In the Statement Property Builder dialog box, type Goodbye in the Main box, and then click OK.
Right-click askDrinkType, and then click Property Builder.
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
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.
This specifies a speech grammar.
Repeat the operation on the DTMF Grammar node.
This selection specifies a DTMF grammar.
Build the solution.
Add Speech Events and Code
Add activities to the SpeechEvents Handler.
To add speech event activities and code
In the lower left corner of Workflow Designer, click View Speech Events.
In the Toolbox, drag and drop a ConsecutiveNoRecognitionsSpeechEvent speech dialog component onto Drop a SpeechEvent Here.
In the Properties window, set MaximumNorecognitions to 4.
In the Toolbox, drag and drop a Statement speech dialog component onto Drop Activities Here.
Set the Name property to noInputError, and then type Thanks for calling Fourth Coffee as the main prompt.
In the Toolbox, drag and drop a GoTo speech dialog component onto Drop Activities Here.
Set the Name property to goToFinishActivity.
Right-click goToFinishActivity, and then click Property Builder.
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
In Solution Explorer, right-click VoiceResponseWorkflow1.cs, and then click View Code.
Right-click askDrinkType, and then click Generate Handlers.
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++;
Add the following statement at the top of the class, between the class declaration and the Workflow1 class constructor.
private int count;
Build the project, and then resolve any errors.
Run the Application
To build and run the application
Press F5 to open the debugger.
In the Voice Response Debugging Window dialog box, click Call.
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.
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.
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.
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