Authoring Grammars
In the Microsoft Visual Studio development system, use Grammar class members to create grammars in code for Microsoft Unified Communications Managed API (UCMA) applications.
Grammars are used by communications workflow applications to recognize user inputs in three modes: speech, instant message (IM), and DTMF (Dual-Tone Multiple-Frequency). Grammars authored for speech recognition will recognize text input in IM mode. Recognizing DTMF inputs requires a separate grammar.
The following activities all use grammars, and the process for adding a grammar to these activities is identical.
SpeechQuestionAnswerActivity
SpeechHelpCommandActivity
SpeechCommandActivity
SpeechRepeatCommandActivity
InstantMessagingQuestionAnswerActivity
InstantMessagingHelpCommandActivity
InstantMessagingCommandActivity
Library Grammars
A library grammar contains a collection of preconstructed grammar rulesets. Each ruleset contains a number of publicly scoped rules that are designed to recognize spoken input for a specific type of data such as a date, a time, or numbers. A library grammar is provided as a convenience, obviating the need for developers to write their own rules for collecting commonly used data and enabling developers to easily develop more complex grammars based on these types of common data. In addition, many of the individual rules provide built-in validation.
By default, find library grammars at %ProgramFiles%\Lync Server\UCMA SDK 3.0\Speech\Sample Applications\Speech\Grammar Files. Add grammar files by setting the appropriate property value in the Properties window. Paths for multiple files are semi-colon delimited. Grammar rules are indicated by appending a pound sign and the rule name to the grammar file path, for example c:/Library.grxml#Ordinal. For more information, see the following procedure.
The following procedure uses a SpeechQuestionAnswerActivity activity and works similarly with other activities that use grammars.
Add .grxml grammars using library grammars
The following steps are sufficient for Visual Studio 2008. However, additional steps are required to develop UCMA workflows in Visual Studio 2010.
In Visual Studio, create a new communications workflow project.
In the Visual Studio Toolbox, expand Unified Communications Workflow to display speech activities.
Drag and drop a SpeechQuestionAnswer activity from the Toolbox onto the design surface in communicationsSequenceActivity1 above disconnectCallActivity1.
In the Properties window, double-click the Grammars property and enter the path to the library grammar. Multiple paths are semi-colon delimited.
Create a Grammar
The following procedure uses a SpeechQuestionAnswerActivity activity and works equally well with an InstantMessagingQuestionAnswerActivity activity.
To create a grammar in code
The following steps are sufficient for Visual Studio 2008. However, additional steps are required to develop UCMA workflows in Visual Studio 2010.
In Visual Studio, create a new communications workflow project.
In the Visual Studio Toolbox, expand Unified Communications Workflow to display speech activities.
Drag and drop a SpeechQuestionAnswer activity from the Toolbox onto the design surface in communicationsSequenceActivity1 above disconnectCallActivity1.
In the Properties window, expand Prompts and set What color? as the value for the MainPrompt property.
In Solution Explorer, right-click Workflow1.xoml.cs and then click View Code.
In the Code window, add the following using statements.
using Microsoft.Speech.Recognition; using Microsoft.Speech.Recognition.SrgsGrammar; using System.Xml;
Add the following procedure at the bottom of the Workflow class.
private Grammar CreateGrammar() { string[] colors = new string[3]; colors[0] = "red"; colors[1] = "blue"; colors[2] = "green"; SrgsDocument colorsGrammar = new SrgsDocument(); colorsGrammar.Mode = SrgsGrammarMode.Voice; SrgsRule rule = new SrgsRule("Items"); SrgsOneOf oneOf = new SrgsOneOf(colors); rule.Elements.Add(oneOf); colorsGrammar.Rules.Add(rule); colorsGrammar.Root = rule; Grammar newGrammar = new Grammar(colorsGrammar); return newGrammar; }
On the design surface, right-click speechQuestionAnswerActivity1 and then click Generate Handlers.
In the event handler, add the following statements.
this.speechQuestionAnswerActivity1.Grammars.Clear(); Grammar colorsGrammar = CreateGrammar(); this.speechQuestionAnswerActivity1.Grammars.Add(colorsGrammar);
To build and debug the application
Create a debugging environment. For information about creating a debugging environment, see Provision and Deploy a UCMA Workflow Application.
Debug the application. For information about debugging applications, see Walkthrough: Debugging a Communications Workflow Application.
Specify Inputs
Instead of attaching a grammar file, you can also specify the expected user inputs directly in the Properties window. The following table lists the properties and activities that support recognition of user input.
Activity |
Property Name |
Description |
---|---|---|
SpeechQuestionAnswerActivity |
ExpectedSpeechInputs |
An array of speech keywords that this activity will recognize. |
SpeechQuestionAnswerActivity |
ExpectedDtmfInputs |
An array of DTMF keywords that this activity will recognize. |
SpeechCommandActivity |
ExpectedSpeechInputs |
An array of speech keywords that will trigger this command. |
SpeechCommandActivity |
ExpectedDtmfInputs |
An array of DTMF keywords that will trigger this command. |
SpeechHelpCommandActivity |
ExpectedSpeechInputs |
An array of speech keywords that will trigger this command. |
SpeechHelpCommandActivity |
ExpectedDtmfInputs |
An array of DTMF keywords that will trigger this command. |
SpeechRepeatCommandActivity |
ExpectedSpeechInputs |
An array of speech keywords that will trigger this command. |
SpeechRepeatCommandActivity |
ExpectedDtmfInputs |
An array of DTMF keywords that will trigger this command. |
InstantMessagingQuestionAnswerActivity |
ExpectedInputs |
An array of IM keywords that will trigger this command. |
InstantMessagingCommandActivity |
ExpectedInputs |
An array of IM keywords that will trigger this command. |
InstantMessagingHelpCommandActivity |
ExpectedInputs |
An array of IM keywords that will trigger this command. |
The following procedure uses the SpeechQuestionAnswerActivity.ExpectedSpeechInputs property and works equally well with the other properties listed in the previous table.
To insert expected inputs
The following steps are sufficient for Visual Studio 2008. However, additional steps are required to develop UCMA workflows in Visual Studio 2010.
In Visual Studio, create a new communications workflow project.
In the Visual Studio Toolbox, expand Unified Communications Workflow to display workflow activities.
Drag and drop a SpeechQuestionAnswer activity from the Toolbox onto the design surface in communicationsSequenceActivity1 above disconnectCallActivity1.
In the Properties window, on the ExpectedSpeechInputs property, click the Browse button.
In String Collection Editor, enter the words red, green, and blue (situate each word on a separate line), and then click OK.
See Also
Other Resources
Unified Communications Managed API 3.0 Workflow SDK Documentation